@bobtail.software/b-ssr 1.0.79 → 1.0.80

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- "use strict";var D=Object.create;var y=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var O=Object.getPrototypeOf,G=Object.prototype.hasOwnProperty;var b=(e,r)=>{for(var a in r)y(e,a,{get:r[a],enumerable:!0})},w=(e,r,a,f)=>{if(r&&typeof r=="object"||typeof r=="function")for(let d of A(r))!G.call(e,d)&&d!==a&&y(e,d,{get:()=>r[d],enumerable:!(f=P(r,d))||f.enumerable});return e};var S=(e,r,a)=>(a=e!=null?D(O(e)):{},w(r||!e||!e.__esModule?y(a,"default",{value:e,enumerable:!0}):a,e)),k=e=>w(y({},"__esModule",{value:!0}),e);var C={};b(C,{default:()=>L});module.exports=k(C);var H=require("@fastify/multipart"),E=S(require("fastify-plugin"),1),T=S(require("path"),1);async function x(e=24678){let r=await import("net");return new Promise((a,f)=>{let d=r.createServer();d.listen(e,"127.0.0.1",()=>{let t=d.address(),o=typeof t=="object"&&t!==null?t.port:e;d.close(()=>a(o))}),d.on("error",t=>{t.code==="EADDRINUSE"?d.close(()=>a(x(e+1))):f(t)})})}function v(e){if(e)return e}var F=async(e,r)=>{if(console.log("[MULTIPART] Hook starting"),!e.isMultipart())return console.log("[MULTIPART] Not multipart, returning 415"),r.status(415).send({statusCode:415,error:"Unsupported Media Type",message:"Multipart/form-data expected"});console.log("[MULTIPART] isMultipart is true, calling req.parts()");try{let a=e.parts(),f={},d=Symbol.for("file-stream");console.log("[MULTIPART] Iterating using next()");let t=await a.next(),o=0;for(;!t.done;){let n=t.value;o++,console.log("[MULTIPART] Part:",n.type,n.fieldname||n.filename),n.type==="field"?f[n.fieldname]=n.value:n.type==="file"&&(console.log("[MULTIPART] File:",n.filename,n.mimetype),e[d]=n),t=await a.next()}console.log("[MULTIPART] Total parts:",o),console.log("[MULTIPART] Body:",f),e.body=f,console.log("[MULTIPART] Hook completed successfully")}catch(a){throw console.log("[MULTIPART] ERROR in hook:",a),a}},M=async(e,r)=>{let a=t=>{if(r.errorHandler){let o=r.errorHandler(t);if(o)return o}return{message:t instanceof Error?t.message:"Internal Server Error",statusCode:500}};if(e.hasDecorator("viteInitDone")&&e.viteInitDone)return;if(!e.hasDecorator("multipartErrors"))try{let t=await import("@fastify/multipart");await e.register(t.default)}catch(t){if(t.code!=="FST_ERR_DEC_ALREADY_PRESENT")throw t}let f=process.env.NODE_ENV==="production";if(f){if(r.clientDistDir)try{let t=await import("@fastify/static"),o=T.default.resolve(r.root,r.clientDistDir);await e.register(t.default,{root:o,wildcard:!1}),console.log(`\u{1F4C2} [Fastify-SSR] Serving static assets from: ${o}`)}catch(t){console.error("\u274C [Fastify-SSR] Error registering @fastify/static. Did you install it?",t)}}else{if(!e.hasDecorator("use"))try{let l=await import("@fastify/middie");await e.register(l.default,{hook:"onRequest"})}catch(l){if(l.code!=="FST_ERR_DEC_ALREADY_PRESENT")throw l}let t=await import("vite"),o=r.viteConfig||{},n;o.server?.hmr&&typeof o.server.hmr=="object"&&"port"in o.server.hmr?n=o.server.hmr.port:n=r.hmrPort??await x();let h=await t.createServer({root:r.root,appType:"custom",...o,server:{hmr:{port:n},...o.server,middlewareMode:!0}});e.use(h.middlewares),e.hasDecorator("viteServer")||e.decorate("viteServer",h),console.log("\u{1F680} [Fastify-SSR] Vite Dev Server Ready")}e.decorate("viteInitDone",!0);let d=async(t,o,n)=>{try{let h=t.raw.url,l=r.getGlobalSettings?await r.getGlobalSettings(t):void 0;if(T.default.extname(h)!==""){o.status(404).send(`File not found: ${h}`);return}let i="";!f&&e.viteServer&&(i=await e.viteServer.transformIndexHtml(h,"<html><head></head><body></body></html>"),i=i.substring(i.indexOf("<head>")+6,i.indexOf("</head>"))),i=(l?`<script>window.__GLOBAL_SETTINGS__ = ${JSON.stringify(l)}</script>`:"")+i;let u=f?await import(T.default.resolve(r.root,r.prodEntryFile)):await e.viteServer.ssrLoadModule(r.devEntryFile),s=u.render||u.default;if(typeof s!="function")throw new Error(`Entry file ${r.devEntryFile} must export a 'render' function.`);await s({req:t,reply:o,head:i,data:n,globalSettings:l})}catch(h){e.viteServer?.ssrFixStacktrace(h),console.error("[SSR Error]:",h),o.sent||o.status(500).send("Internal Server Error")}};e.decorate("addRpcRoute",function(t,o){let{handler:n,schema:h,...l}=o,i=`/rpc${t}`,p=v(h),u={...l,schema:p},s=o?.schema?.consumes?.includes("multipart/form-data");if(s&&console.log("[ADD_ROUTE] Adding multipart preValidation hook for:",t),s){let c=u.preValidation;u.preValidation=c?Array.isArray(c)?[F,...c]:[F,c]:F}this.route({method:"POST",url:i,...u,handler:async(c,m)=>{try{let R=await n.call(this,c,m);return m.sent?void 0:R}catch(R){if(console.error(`[RPC Error] ${i}:`,R),!m.sent){let{statusCode:g,message:I}=a(R);m.status(g).send({error:{message:I}})}}}})}),e.decorate("addRenderRoute",function(t,o){let{handler:n,schema:h,...l}=o||{},i=v(h),p=async(u,s,c)=>{try{let m=await n?.call(this,u,s);return c?m:d(u,s,m)}catch(m){if(console.error(`[Render Error] ${t}:`,m),!s.sent){let{statusCode:R,message:g}=a(m);if(c)s.status(R).send({error:{message:g}});else return d(u,s,{ssrError:{statusCode:500,message:"Internal Error"}})}}};if(this.route({method:"GET",url:t,schema:i,...l,handler:(u,s)=>p(u,s,!1)}),t!=="*"&&t!=="/*"){this.route({method:"GET",url:`/loader${t}`,schema:i,...l,handler:(c,m)=>p(c,m,!0)});let u=t.endsWith("/")?"*":"/*",s=`${t}${u}`;this.route({method:"GET",url:s,schema:i,...l,handler:(c,m)=>p(c,m,!1)})}}),e.decorate("addLoaderRoute",function(t,o){let{handler:n,schema:h,...l}=o,i=`/api${t}`,p=v(h);this.route({method:"GET",url:i,schema:p,...l,handler:async(u,s)=>{try{let c=await n.call(this,u,s);return s.sent?void 0:c}catch(c){if(console.error(`[Loader API Error] ${i}:`,c),!s.sent){let{statusCode:m,message:R}=a(c);s.status(m).send({error:{message:R}})}}}})})},L=(0,E.default)(M,{name:"fastify-b-ssr"});
1
+ "use strict";var P=Object.create;var S=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var O=Object.getPrototypeOf,M=Object.prototype.hasOwnProperty;var G=(e,r)=>{for(var a in r)S(e,a,{get:r[a],enumerable:!0})},w=(e,r,a,f)=>{if(r&&typeof r=="object"||typeof r=="function")for(let d of D(r))!M.call(e,d)&&d!==a&&S(e,d,{get:()=>r[d],enumerable:!(f=A(r,d))||f.enumerable});return e};var y=(e,r,a)=>(a=e!=null?P(O(e)):{},w(r||!e||!e.__esModule?S(a,"default",{value:e,enumerable:!0}):a,e)),b=e=>w(S({},"__esModule",{value:!0}),e);var U={};G(U,{default:()=>k});module.exports=b(U);var H=require("@fastify/multipart"),E=y(require("fastify-plugin"),1),T=y(require("path"),1);async function I(e=24678){let r=await import("net");return new Promise((a,f)=>{let d=r.createServer();d.listen(e,"127.0.0.1",()=>{let t=d.address(),o=typeof t=="object"&&t!==null?t.port:e;d.close(()=>a(o))}),d.on("error",t=>{t.code==="EADDRINUSE"?d.close(()=>a(I(e+1))):f(t)})})}function v(e){if(e)return e}var F=async(e,r)=>{if(console.log("[MULTIPART] Hook starting"),!e.isMultipart())return console.log("[MULTIPART] Not multipart, returning 415"),r.status(415).send({statusCode:415,error:"Unsupported Media Type",message:"Multipart/form-data expected"});console.log("[MULTIPART] isMultipart is true, calling req.parts()");try{let a=e.parts();console.log("[MULTIPART] parts type:",typeof a,a);let f={},d=Symbol.for("file-stream");console.log("[MULTIPART] Iterating using next()"),console.log("[MULTIPART] Trying parts() as function...");try{typeof a=="function"&&console.log("[MULTIPART] parts is a function, calling it")}catch(n){console.log("[MULTIPART] parts check error:",n)}let t=await a.next();console.log("[MULTIPART] First next() result:",t);let o=0;for(;!t.done;){let n=t.value;o++,console.log("[MULTIPART] Part:",n.type,n.fieldname||n.filename),n.type==="field"?f[n.fieldname]=n.value:n.type==="file"&&(console.log("[MULTIPART] File:",n.filename,n.mimetype),e[d]=n),t=await a.next()}console.log("[MULTIPART] Total parts:",o),console.log("[MULTIPART] Body:",f),e.body=f,console.log("[MULTIPART] Hook completed successfully")}catch(a){throw console.log("[MULTIPART] ERROR in hook:",a),a}},L=async(e,r)=>{let a=t=>{if(r.errorHandler){let o=r.errorHandler(t);if(o)return o}return{message:t instanceof Error?t.message:"Internal Server Error",statusCode:500}};if(e.hasDecorator("viteInitDone")&&e.viteInitDone)return;if(!e.hasDecorator("multipartErrors"))try{let t=await import("@fastify/multipart");await e.register(t.default)}catch(t){if(t.code!=="FST_ERR_DEC_ALREADY_PRESENT")throw t}let f=process.env.NODE_ENV==="production";if(f){if(r.clientDistDir)try{let t=await import("@fastify/static"),o=T.default.resolve(r.root,r.clientDistDir);await e.register(t.default,{root:o,wildcard:!1}),console.log(`\u{1F4C2} [Fastify-SSR] Serving static assets from: ${o}`)}catch(t){console.error("\u274C [Fastify-SSR] Error registering @fastify/static. Did you install it?",t)}}else{if(!e.hasDecorator("use"))try{let l=await import("@fastify/middie");await e.register(l.default,{hook:"onRequest"})}catch(l){if(l.code!=="FST_ERR_DEC_ALREADY_PRESENT")throw l}let t=await import("vite"),o=r.viteConfig||{},n;o.server?.hmr&&typeof o.server.hmr=="object"&&"port"in o.server.hmr?n=o.server.hmr.port:n=r.hmrPort??await I();let h=await t.createServer({root:r.root,appType:"custom",...o,server:{hmr:{port:n},...o.server,middlewareMode:!0}});e.use(h.middlewares),e.hasDecorator("viteServer")||e.decorate("viteServer",h),console.log("\u{1F680} [Fastify-SSR] Vite Dev Server Ready")}e.decorate("viteInitDone",!0);let d=async(t,o,n)=>{try{let h=t.raw.url,l=r.getGlobalSettings?await r.getGlobalSettings(t):void 0;if(T.default.extname(h)!==""){o.status(404).send(`File not found: ${h}`);return}let i="";!f&&e.viteServer&&(i=await e.viteServer.transformIndexHtml(h,"<html><head></head><body></body></html>"),i=i.substring(i.indexOf("<head>")+6,i.indexOf("</head>"))),i=(l?`<script>window.__GLOBAL_SETTINGS__ = ${JSON.stringify(l)}</script>`:"")+i;let u=f?await import(T.default.resolve(r.root,r.prodEntryFile)):await e.viteServer.ssrLoadModule(r.devEntryFile),s=u.render||u.default;if(typeof s!="function")throw new Error(`Entry file ${r.devEntryFile} must export a 'render' function.`);await s({req:t,reply:o,head:i,data:n,globalSettings:l})}catch(h){e.viteServer?.ssrFixStacktrace(h),console.error("[SSR Error]:",h),o.sent||o.status(500).send("Internal Server Error")}};e.decorate("addRpcRoute",function(t,o){let{handler:n,schema:h,...l}=o,i=`/rpc${t}`,p=v(h),u={...l,schema:p},s=o?.schema?.consumes?.includes("multipart/form-data");if(s&&console.log("[ADD_ROUTE] Adding multipart preValidation hook for:",t),s){let c=u.preValidation;u.preValidation=c?Array.isArray(c)?[F,...c]:[F,c]:F}this.route({method:"POST",url:i,...u,handler:async(c,m)=>{try{let R=await n.call(this,c,m);return m.sent?void 0:R}catch(R){if(console.error(`[RPC Error] ${i}:`,R),!m.sent){let{statusCode:g,message:x}=a(R);m.status(g).send({error:{message:x}})}}}})}),e.decorate("addRenderRoute",function(t,o){let{handler:n,schema:h,...l}=o||{},i=v(h),p=async(u,s,c)=>{try{let m=await n?.call(this,u,s);return c?m:d(u,s,m)}catch(m){if(console.error(`[Render Error] ${t}:`,m),!s.sent){let{statusCode:R,message:g}=a(m);if(c)s.status(R).send({error:{message:g}});else return d(u,s,{ssrError:{statusCode:500,message:"Internal Error"}})}}};if(this.route({method:"GET",url:t,schema:i,...l,handler:(u,s)=>p(u,s,!1)}),t!=="*"&&t!=="/*"){this.route({method:"GET",url:`/loader${t}`,schema:i,...l,handler:(c,m)=>p(c,m,!0)});let u=t.endsWith("/")?"*":"/*",s=`${t}${u}`;this.route({method:"GET",url:s,schema:i,...l,handler:(c,m)=>p(c,m,!1)})}}),e.decorate("addLoaderRoute",function(t,o){let{handler:n,schema:h,...l}=o,i=`/api${t}`,p=v(h);this.route({method:"GET",url:i,schema:p,...l,handler:async(u,s)=>{try{let c=await n.call(this,u,s);return s.sent?void 0:c}catch(c){if(console.error(`[Loader API Error] ${i}:`,c),!s.sent){let{statusCode:m,message:R}=a(c);s.status(m).send({error:{message:R}})}}}})})},k=(0,E.default)(L,{name:"fastify-b-ssr"});
@@ -1 +1 @@
1
- import"@fastify/multipart";import w from"fastify-plugin";import y from"path";async function v(t=24678){let a=await import("net");return new Promise((m,f)=>{let h=a.createServer();h.listen(t,"127.0.0.1",()=>{let e=h.address(),r=typeof e=="object"&&e!==null?e.port:t;h.close(()=>m(r))}),h.on("error",e=>{e.code==="EADDRINUSE"?h.close(()=>m(v(t+1))):f(e)})})}function T(t){if(t)return t}var g=async(t,a)=>{if(console.log("[MULTIPART] Hook starting"),!t.isMultipart())return console.log("[MULTIPART] Not multipart, returning 415"),a.status(415).send({statusCode:415,error:"Unsupported Media Type",message:"Multipart/form-data expected"});console.log("[MULTIPART] isMultipart is true, calling req.parts()");try{let m=t.parts(),f={},h=Symbol.for("file-stream");console.log("[MULTIPART] Iterating using next()");let e=await m.next(),r=0;for(;!e.done;){let o=e.value;r++,console.log("[MULTIPART] Part:",o.type,o.fieldname||o.filename),o.type==="field"?f[o.fieldname]=o.value:o.type==="file"&&(console.log("[MULTIPART] File:",o.filename,o.mimetype),t[h]=o),e=await m.next()}console.log("[MULTIPART] Total parts:",r),console.log("[MULTIPART] Body:",f),t.body=f,console.log("[MULTIPART] Hook completed successfully")}catch(m){throw console.log("[MULTIPART] ERROR in hook:",m),m}},E=async(t,a)=>{let m=e=>{if(a.errorHandler){let r=a.errorHandler(e);if(r)return r}return{message:e instanceof Error?e.message:"Internal Server Error",statusCode:500}};if(t.hasDecorator("viteInitDone")&&t.viteInitDone)return;if(!t.hasDecorator("multipartErrors"))try{let e=await import("@fastify/multipart");await t.register(e.default)}catch(e){if(e.code!=="FST_ERR_DEC_ALREADY_PRESENT")throw e}let f=process.env.NODE_ENV==="production";if(f){if(a.clientDistDir)try{let e=await import("@fastify/static"),r=y.resolve(a.root,a.clientDistDir);await t.register(e.default,{root:r,wildcard:!1}),console.log(`\u{1F4C2} [Fastify-SSR] Serving static assets from: ${r}`)}catch(e){console.error("\u274C [Fastify-SSR] Error registering @fastify/static. Did you install it?",e)}}else{if(!t.hasDecorator("use"))try{let c=await import("@fastify/middie");await t.register(c.default,{hook:"onRequest"})}catch(c){if(c.code!=="FST_ERR_DEC_ALREADY_PRESENT")throw c}let e=await import("vite"),r=a.viteConfig||{},o;r.server?.hmr&&typeof r.server.hmr=="object"&&"port"in r.server.hmr?o=r.server.hmr.port:o=a.hmrPort??await v();let u=await e.createServer({root:a.root,appType:"custom",...r,server:{hmr:{port:o},...r.server,middlewareMode:!0}});t.use(u.middlewares),t.hasDecorator("viteServer")||t.decorate("viteServer",u),console.log("\u{1F680} [Fastify-SSR] Vite Dev Server Ready")}t.decorate("viteInitDone",!0);let h=async(e,r,o)=>{try{let u=e.raw.url,c=a.getGlobalSettings?await a.getGlobalSettings(e):void 0;if(y.extname(u)!==""){r.status(404).send(`File not found: ${u}`);return}let s="";!f&&t.viteServer&&(s=await t.viteServer.transformIndexHtml(u,"<html><head></head><body></body></html>"),s=s.substring(s.indexOf("<head>")+6,s.indexOf("</head>"))),s=(c?`<script>window.__GLOBAL_SETTINGS__ = ${JSON.stringify(c)}</script>`:"")+s;let d=f?await import(y.resolve(a.root,a.prodEntryFile)):await t.viteServer.ssrLoadModule(a.devEntryFile),n=d.render||d.default;if(typeof n!="function")throw new Error(`Entry file ${a.devEntryFile} must export a 'render' function.`);await n({req:e,reply:r,head:s,data:o,globalSettings:c})}catch(u){t.viteServer?.ssrFixStacktrace(u),console.error("[SSR Error]:",u),r.sent||r.status(500).send("Internal Server Error")}};t.decorate("addRpcRoute",function(e,r){let{handler:o,schema:u,...c}=r,s=`/rpc${e}`,p=T(u),d={...c,schema:p},n=r?.schema?.consumes?.includes("multipart/form-data");if(n&&console.log("[ADD_ROUTE] Adding multipart preValidation hook for:",e),n){let i=d.preValidation;d.preValidation=i?Array.isArray(i)?[g,...i]:[g,i]:g}this.route({method:"POST",url:s,...d,handler:async(i,l)=>{try{let R=await o.call(this,i,l);return l.sent?void 0:R}catch(R){if(console.error(`[RPC Error] ${s}:`,R),!l.sent){let{statusCode:S,message:F}=m(R);l.status(S).send({error:{message:F}})}}}})}),t.decorate("addRenderRoute",function(e,r){let{handler:o,schema:u,...c}=r||{},s=T(u),p=async(d,n,i)=>{try{let l=await o?.call(this,d,n);return i?l:h(d,n,l)}catch(l){if(console.error(`[Render Error] ${e}:`,l),!n.sent){let{statusCode:R,message:S}=m(l);if(i)n.status(R).send({error:{message:S}});else return h(d,n,{ssrError:{statusCode:500,message:"Internal Error"}})}}};if(this.route({method:"GET",url:e,schema:s,...c,handler:(d,n)=>p(d,n,!1)}),e!=="*"&&e!=="/*"){this.route({method:"GET",url:`/loader${e}`,schema:s,...c,handler:(i,l)=>p(i,l,!0)});let d=e.endsWith("/")?"*":"/*",n=`${e}${d}`;this.route({method:"GET",url:n,schema:s,...c,handler:(i,l)=>p(i,l,!1)})}}),t.decorate("addLoaderRoute",function(e,r){let{handler:o,schema:u,...c}=r,s=`/api${e}`,p=T(u);this.route({method:"GET",url:s,schema:p,...c,handler:async(d,n)=>{try{let i=await o.call(this,d,n);return n.sent?void 0:i}catch(i){if(console.error(`[Loader API Error] ${s}:`,i),!n.sent){let{statusCode:l,message:R}=m(i);n.status(l).send({error:{message:R}})}}}})})},P=w(E,{name:"fastify-b-ssr"});export{P as default};
1
+ import"@fastify/multipart";import w from"fastify-plugin";import S from"path";async function v(t=24678){let a=await import("net");return new Promise((u,f)=>{let h=a.createServer();h.listen(t,"127.0.0.1",()=>{let e=h.address(),r=typeof e=="object"&&e!==null?e.port:t;h.close(()=>u(r))}),h.on("error",e=>{e.code==="EADDRINUSE"?h.close(()=>u(v(t+1))):f(e)})})}function T(t){if(t)return t}var g=async(t,a)=>{if(console.log("[MULTIPART] Hook starting"),!t.isMultipart())return console.log("[MULTIPART] Not multipart, returning 415"),a.status(415).send({statusCode:415,error:"Unsupported Media Type",message:"Multipart/form-data expected"});console.log("[MULTIPART] isMultipart is true, calling req.parts()");try{let u=t.parts();console.log("[MULTIPART] parts type:",typeof u,u);let f={},h=Symbol.for("file-stream");console.log("[MULTIPART] Iterating using next()"),console.log("[MULTIPART] Trying parts() as function...");try{typeof u=="function"&&console.log("[MULTIPART] parts is a function, calling it")}catch(o){console.log("[MULTIPART] parts check error:",o)}let e=await u.next();console.log("[MULTIPART] First next() result:",e);let r=0;for(;!e.done;){let o=e.value;r++,console.log("[MULTIPART] Part:",o.type,o.fieldname||o.filename),o.type==="field"?f[o.fieldname]=o.value:o.type==="file"&&(console.log("[MULTIPART] File:",o.filename,o.mimetype),t[h]=o),e=await u.next()}console.log("[MULTIPART] Total parts:",r),console.log("[MULTIPART] Body:",f),t.body=f,console.log("[MULTIPART] Hook completed successfully")}catch(u){throw console.log("[MULTIPART] ERROR in hook:",u),u}},E=async(t,a)=>{let u=e=>{if(a.errorHandler){let r=a.errorHandler(e);if(r)return r}return{message:e instanceof Error?e.message:"Internal Server Error",statusCode:500}};if(t.hasDecorator("viteInitDone")&&t.viteInitDone)return;if(!t.hasDecorator("multipartErrors"))try{let e=await import("@fastify/multipart");await t.register(e.default)}catch(e){if(e.code!=="FST_ERR_DEC_ALREADY_PRESENT")throw e}let f=process.env.NODE_ENV==="production";if(f){if(a.clientDistDir)try{let e=await import("@fastify/static"),r=S.resolve(a.root,a.clientDistDir);await t.register(e.default,{root:r,wildcard:!1}),console.log(`\u{1F4C2} [Fastify-SSR] Serving static assets from: ${r}`)}catch(e){console.error("\u274C [Fastify-SSR] Error registering @fastify/static. Did you install it?",e)}}else{if(!t.hasDecorator("use"))try{let c=await import("@fastify/middie");await t.register(c.default,{hook:"onRequest"})}catch(c){if(c.code!=="FST_ERR_DEC_ALREADY_PRESENT")throw c}let e=await import("vite"),r=a.viteConfig||{},o;r.server?.hmr&&typeof r.server.hmr=="object"&&"port"in r.server.hmr?o=r.server.hmr.port:o=a.hmrPort??await v();let m=await e.createServer({root:a.root,appType:"custom",...r,server:{hmr:{port:o},...r.server,middlewareMode:!0}});t.use(m.middlewares),t.hasDecorator("viteServer")||t.decorate("viteServer",m),console.log("\u{1F680} [Fastify-SSR] Vite Dev Server Ready")}t.decorate("viteInitDone",!0);let h=async(e,r,o)=>{try{let m=e.raw.url,c=a.getGlobalSettings?await a.getGlobalSettings(e):void 0;if(S.extname(m)!==""){r.status(404).send(`File not found: ${m}`);return}let s="";!f&&t.viteServer&&(s=await t.viteServer.transformIndexHtml(m,"<html><head></head><body></body></html>"),s=s.substring(s.indexOf("<head>")+6,s.indexOf("</head>"))),s=(c?`<script>window.__GLOBAL_SETTINGS__ = ${JSON.stringify(c)}</script>`:"")+s;let d=f?await import(S.resolve(a.root,a.prodEntryFile)):await t.viteServer.ssrLoadModule(a.devEntryFile),n=d.render||d.default;if(typeof n!="function")throw new Error(`Entry file ${a.devEntryFile} must export a 'render' function.`);await n({req:e,reply:r,head:s,data:o,globalSettings:c})}catch(m){t.viteServer?.ssrFixStacktrace(m),console.error("[SSR Error]:",m),r.sent||r.status(500).send("Internal Server Error")}};t.decorate("addRpcRoute",function(e,r){let{handler:o,schema:m,...c}=r,s=`/rpc${e}`,p=T(m),d={...c,schema:p},n=r?.schema?.consumes?.includes("multipart/form-data");if(n&&console.log("[ADD_ROUTE] Adding multipart preValidation hook for:",e),n){let i=d.preValidation;d.preValidation=i?Array.isArray(i)?[g,...i]:[g,i]:g}this.route({method:"POST",url:s,...d,handler:async(i,l)=>{try{let R=await o.call(this,i,l);return l.sent?void 0:R}catch(R){if(console.error(`[RPC Error] ${s}:`,R),!l.sent){let{statusCode:y,message:F}=u(R);l.status(y).send({error:{message:F}})}}}})}),t.decorate("addRenderRoute",function(e,r){let{handler:o,schema:m,...c}=r||{},s=T(m),p=async(d,n,i)=>{try{let l=await o?.call(this,d,n);return i?l:h(d,n,l)}catch(l){if(console.error(`[Render Error] ${e}:`,l),!n.sent){let{statusCode:R,message:y}=u(l);if(i)n.status(R).send({error:{message:y}});else return h(d,n,{ssrError:{statusCode:500,message:"Internal Error"}})}}};if(this.route({method:"GET",url:e,schema:s,...c,handler:(d,n)=>p(d,n,!1)}),e!=="*"&&e!=="/*"){this.route({method:"GET",url:`/loader${e}`,schema:s,...c,handler:(i,l)=>p(i,l,!0)});let d=e.endsWith("/")?"*":"/*",n=`${e}${d}`;this.route({method:"GET",url:n,schema:s,...c,handler:(i,l)=>p(i,l,!1)})}}),t.decorate("addLoaderRoute",function(e,r){let{handler:o,schema:m,...c}=r,s=`/api${e}`,p=T(m);this.route({method:"GET",url:s,schema:p,...c,handler:async(d,n)=>{try{let i=await o.call(this,d,n);return n.sent?void 0:i}catch(i){if(console.error(`[Loader API Error] ${s}:`,i),!n.sent){let{statusCode:l,message:R}=u(i);n.status(l).send({error:{message:R}})}}}})})},A=w(E,{name:"fastify-b-ssr"});export{A as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bobtail.software/b-ssr",
3
- "version": "1.0.79",
3
+ "version": "1.0.80",
4
4
  "description": "Fastify + Vite SSR Plugin wrapper with RPC",
5
5
  "author": "Victor Moreno <info@bobtail.software> (https://bobtail.software)",
6
6
  "license": "GPL-3.0",