@lomray/vite-ssr-boost 2.3.0 → 2.3.1

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.
package/node/server.js CHANGED
@@ -1,2 +1,2 @@
1
- import e from"path";import r from"compression";import t from"express";import s from"../helpers/print-server-info.js";import o from"../services/prepare-server.js";async function i(i){const a=t().disable("x-powered-by");if(i.setApp(a),i.isProd){const{root:s,publicDir:o,isSPA:n}=i.getParams();a.use(r()),n||a.use(((e,r,t)=>{"/index.html"===e.url&&(e.url="/index-not-found.html"),t()})),a.use(t.static(e.resolve(`${s}/${o}`),{index:!!n&&void 0}))}else{const e=await(await import("vite")).createServer({server:{middlewareMode:!0,watch:{usePolling:!0,interval:100}},appType:"custom",mode:i.mode});a.use(e.middlewares),i.setVite(e)}const n=o.init(i);return i.isSPA?a.use("*",((e,r,t)=>{(async()=>{try{const t=(await n.loadHtml(e)).join("");r.send(t)}catch(e){t(e)}})()})):(await n.onAppCreated(),a.use("*",((e,r,t)=>{(async()=>{try{const[{render:t,onRequest:s,...o},a]=await Promise.all([n.loadEntrypoint(),n.loadHtml(e)]),{appProps:p,hasEarlyHints:l}=await(s?.(e,r))??{},[m,c]=a,d={req:e,res:r,hasEarlyHints:l,appProps:p??{},html:{header:m,footer:c}};await t(i,d,o)}catch(e){t(e)}})()}))),{run:({version:e,isPrintInfo:r=!0}={})=>{const{port:t,host:o}=i.getParams();i.isHost&&!i.isProd&&(i.getVite().config.server.host=o);const n=a.listen(t,o,(()=>{r&&s(i,{version:e,server:n})}));return n},app:a}}export{i as default};
1
+ import e from"node:http";import r from"node:https";import t from"path";import s from"compression";import o from"express";import i from"../helpers/print-server-info.js";import a from"../services/prepare-server.js";async function n(n){const p=o().disable("x-powered-by");if(n.setApp(p),n.isProd){const{root:e,publicDir:r,isSPA:i}=n.getParams();p.use(s()),i||p.use(((e,r,t)=>{"/index.html"===e.url&&(e.url="/index-not-found.html"),t()})),p.use(o.static(t.resolve(`${e}/${r}`),{index:!!i&&void 0}))}else{const e=await(await import("vite")).createServer({server:{middlewareMode:!0,watch:{usePolling:!0,interval:100}},appType:"custom",mode:n.mode});p.use(e.middlewares),n.setVite(e)}const m=a.init(n);return n.isSPA?p.use("*",((e,r,t)=>{(async()=>{try{const t=(await m.loadHtml(e)).join("");r.send(t)}catch(e){t(e)}})()})):(await m.onAppCreated(),p.use("*",((e,r,t)=>{(async()=>{try{const[{render:t,onRequest:s,...o},i]=await Promise.all([m.loadEntrypoint(),m.loadHtml(e)]),{appProps:a,hasEarlyHints:p}=await(s?.(e,r))??{},[c,l]=i,d={req:e,res:r,hasEarlyHints:p,appProps:a??{},html:{header:c,footer:l}};await t(n,d,o)}catch(e){t(e)}})()}))),{run:({version:t,isPrintInfo:s=!0}={})=>{const{port:o,host:a}=n.getParams(),m=Boolean(n.getVite()?.config?.server?.https);n.isHost&&!n.isProd&&(n.getVite().config.server.host=a);const c=(m?r.createServer(n.getVite().config.server.https,p):e.createServer(p)).listen(o,a,(()=>{s&&i(n,{version:t,server:c})}));return c},app:p}}export{n as default};
2
2
  //# sourceMappingURL=server.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"server.js","sources":["../../src/node/server.ts"],"sourcesContent":["import type { Server } from 'node:net';\nimport path from 'path';\nimport compression from 'compression';\nimport type { Express } from 'express';\nimport express from 'express';\nimport printServerInfo from '@helpers/print-server-info';\nimport type { IRequestContext } from '@node/render';\nimport PrepareServer from '@services/prepare-server';\nimport type ServerConfig from '@services/server-config';\n\nexport interface ICreateServerOut {\n run: (options?: { version?: string; isPrintInfo?: boolean }) => Server;\n app: Express;\n}\n\n/**\n * Create SSR server\n */\nasync function createServer(config: ServerConfig): Promise<ICreateServerOut> {\n const app = express().disable('x-powered-by');\n\n config.setApp(app);\n\n if (!config.isProd) {\n // Create Vite server in middleware mode and configure the app type as\n // 'custom', disabling Vite's own HTML serving logic so parent server\n // can take control\n const vite = await (\n await import('vite')\n ).createServer({\n server: {\n middlewareMode: true,\n watch: {\n // During tests, we edit the files too fast and sometimes chokidar\n // misses change events, so enforce polling for consistency\n usePolling: true,\n interval: 100,\n },\n },\n appType: 'custom',\n mode: config.mode,\n });\n\n // Use vite's connect instance as middleware\n app.use(vite.middlewares);\n\n config.setVite(vite);\n } else {\n const { root, publicDir, isSPA } = config.getParams();\n\n app.use(compression());\n\n if (!isSPA) {\n // ignore index.html file in SSR mode\n app.use((req, _, next) => {\n if (req.url === '/index.html') {\n req.url = '/index-not-found.html';\n }\n\n next();\n });\n }\n\n app.use(\n express.static(path.resolve(`${root}/${publicDir}`), {\n index: isSPA ? undefined : false,\n }),\n );\n }\n\n const prepareServer = PrepareServer.init(config);\n\n // SSR mode\n if (!config.isSPA) {\n await prepareServer.onAppCreated();\n\n app.use('*', (req, res, next) => {\n void (async () => {\n try {\n const [{ render, onRequest, ...renderParams }, clientHtml] = await Promise.all([\n prepareServer.loadEntrypoint(),\n prepareServer.loadHtml(req),\n ]);\n const { appProps, hasEarlyHints } = (await onRequest?.(req, res)) ?? {};\n const [header, footer] = clientHtml;\n\n const context: IRequestContext = {\n req,\n res,\n hasEarlyHints,\n appProps: appProps ?? {},\n html: { header, footer },\n };\n\n await render(config, context, renderParams);\n } catch (e) {\n next(e);\n }\n })();\n });\n } else {\n // SPA mode, redirect any request to index.html\n app.use('*', (req, res, next) => {\n void (async () => {\n try {\n const html = (await prepareServer.loadHtml(req)).join('');\n\n res.send(html);\n } catch (e) {\n next(e);\n }\n })();\n });\n }\n\n return {\n run: ({ version, isPrintInfo = true } = {}): Server => {\n const { port, host } = config.getParams();\n\n // update resolved host for print network link\n if (config.isHost && !config.isProd) {\n config.getVite()!.config.server.host = host;\n }\n\n const server = app.listen(port, host, () => {\n if (!isPrintInfo) {\n return;\n }\n\n void printServerInfo(config, { version, server });\n });\n\n return server;\n },\n app,\n };\n}\n\nexport default createServer;\n"],"names":["async","createServer","config","app","express","disable","setApp","isProd","root","publicDir","isSPA","getParams","use","compression","req","_","next","url","static","path","resolve","index","undefined","vite","import","server","middlewareMode","watch","usePolling","interval","appType","mode","middlewares","setVite","prepareServer","PrepareServer","init","res","html","loadHtml","join","send","e","onAppCreated","render","onRequest","renderParams","clientHtml","Promise","all","loadEntrypoint","appProps","hasEarlyHints","header","footer","context","run","version","isPrintInfo","port","host","isHost","getVite","listen","printServerInfo"],"mappings":"kKAkBAA,eAAeC,EAAaC,GAC1B,MAAMC,EAAMC,IAAUC,QAAQ,gBAI9B,GAFAH,EAAOI,OAAOH,GAETD,EAAOK,OAwBL,CACL,MAAMC,KAAEA,EAAIC,UAAEA,EAASC,MAAEA,GAAUR,EAAOS,YAE1CR,EAAIS,IAAIC,KAEHH,GAEHP,EAAIS,KAAI,CAACE,EAAKC,EAAGC,KACC,gBAAZF,EAAIG,MACNH,EAAIG,IAAM,yBAGZD,GAAM,IAIVb,EAAIS,IACFR,EAAQc,OAAOC,EAAKC,QAAQ,GAAGZ,KAAQC,KAAc,CACnDY,QAAOX,QAAQY,IAGpB,KA7CmB,CAIlB,MAAMC,cACEC,OAAO,SACbvB,aAAa,CACbwB,OAAQ,CACNC,gBAAgB,EAChBC,MAAO,CAGLC,YAAY,EACZC,SAAU,MAGdC,QAAS,SACTC,KAAM7B,EAAO6B,OAIf5B,EAAIS,IAAIW,EAAKS,aAEb9B,EAAO+B,QAAQV,EAChB,CAuBD,MAAMW,EAAgBC,EAAcC,KAAKlC,GA6CzC,OA1CKA,EAAOQ,MA6BVP,EAAIS,IAAI,KAAK,CAACE,EAAKuB,EAAKrB,KACjB,WACH,IACE,MAAMsB,SAAcJ,EAAcK,SAASzB,IAAM0B,KAAK,IAEtDH,EAAII,KAAKH,EACV,CAAC,MAAOI,GACP1B,EAAK0B,EACN,CACF,EARI,EAQD,WArCAR,EAAcS,eAEpBxC,EAAIS,IAAI,KAAK,CAACE,EAAKuB,EAAKrB,KACjB,WACH,IACE,OAAO4B,OAAEA,EAAMC,UAAEA,KAAcC,GAAgBC,SAAoBC,QAAQC,IAAI,CAC7Ef,EAAcgB,iBACdhB,EAAcK,SAASzB,MAEnBqC,SAAEA,EAAQC,cAAEA,SAAyBP,IAAY/B,EAAKuB,KAAS,IAC9DgB,EAAQC,GAAUP,EAEnBQ,EAA2B,CAC/BzC,MACAuB,MACAe,gBACAD,SAAUA,GAAY,CAAE,EACxBb,KAAM,CAAEe,SAAQC,iBAGZV,EAAO1C,EAAQqD,EAAST,EAC/B,CAAC,MAAOJ,GACP1B,EAAK0B,EACN,CACF,EArBI,EAqBD,KAiBD,CACLc,IAAK,EAAGC,UAASC,eAAc,GAAS,CAAA,KACtC,MAAMC,KAAEA,EAAIC,KAAEA,GAAS1D,EAAOS,YAG1BT,EAAO2D,SAAW3D,EAAOK,SAC3BL,EAAO4D,UAAW5D,OAAOuB,OAAOmC,KAAOA,GAGzC,MAAMnC,EAAStB,EAAI4D,OAAOJ,EAAMC,GAAM,KAC/BF,GAIAM,EAAgB9D,EAAQ,CAAEuD,UAAShC,UAAS,IAGnD,OAAOA,CAAM,EAEftB,MAEJ"}
1
+ {"version":3,"file":"server.js","sources":["../../src/node/server.ts"],"sourcesContent":["import http from 'node:http';\nimport https from 'node:https';\nimport type { Server } from 'node:net';\nimport path from 'path';\nimport compression from 'compression';\nimport type { Express } from 'express';\nimport express from 'express';\nimport printServerInfo from '@helpers/print-server-info';\nimport type { IRequestContext } from '@node/render';\nimport PrepareServer from '@services/prepare-server';\nimport type ServerConfig from '@services/server-config';\n\nexport interface ICreateServerOut {\n run: (options?: { version?: string; isPrintInfo?: boolean }) => Server;\n app: Express;\n}\n\n/**\n * Create SSR server\n */\nasync function createServer(config: ServerConfig): Promise<ICreateServerOut> {\n const app = express().disable('x-powered-by');\n\n config.setApp(app);\n\n if (!config.isProd) {\n // Create Vite server in middleware mode and configure the app type as\n // 'custom', disabling Vite's own HTML serving logic so parent server\n // can take control\n const vite = await (\n await import('vite')\n ).createServer({\n server: {\n middlewareMode: true,\n watch: {\n // During tests, we edit the files too fast and sometimes chokidar\n // misses change events, so enforce polling for consistency\n usePolling: true,\n interval: 100,\n },\n },\n appType: 'custom',\n mode: config.mode,\n });\n\n // Use vite's connect instance as middleware\n app.use(vite.middlewares);\n\n config.setVite(vite);\n } else {\n const { root, publicDir, isSPA } = config.getParams();\n\n app.use(compression());\n\n if (!isSPA) {\n // ignore index.html file in SSR mode\n app.use((req, _, next) => {\n if (req.url === '/index.html') {\n req.url = '/index-not-found.html';\n }\n\n next();\n });\n }\n\n app.use(\n express.static(path.resolve(`${root}/${publicDir}`), {\n index: isSPA ? undefined : false,\n }),\n );\n }\n\n const prepareServer = PrepareServer.init(config);\n\n // SSR mode\n if (!config.isSPA) {\n await prepareServer.onAppCreated();\n\n app.use('*', (req, res, next) => {\n void (async () => {\n try {\n const [{ render, onRequest, ...renderParams }, clientHtml] = await Promise.all([\n prepareServer.loadEntrypoint(),\n prepareServer.loadHtml(req),\n ]);\n const { appProps, hasEarlyHints } = (await onRequest?.(req, res)) ?? {};\n const [header, footer] = clientHtml;\n\n const context: IRequestContext = {\n req,\n res,\n hasEarlyHints,\n appProps: appProps ?? {},\n html: { header, footer },\n };\n\n await render(config, context, renderParams);\n } catch (e) {\n next(e);\n }\n })();\n });\n } else {\n // SPA mode, redirect any request to index.html\n app.use('*', (req, res, next) => {\n void (async () => {\n try {\n const html = (await prepareServer.loadHtml(req)).join('');\n\n res.send(html);\n } catch (e) {\n next(e);\n }\n })();\n });\n }\n\n return {\n run: ({ version, isPrintInfo = true } = {}): Server => {\n const { port, host } = config.getParams();\n const isHTTPS = Boolean(config.getVite()?.config?.server?.https);\n\n // update resolved host for print network link\n if (config.isHost && !config.isProd) {\n config.getVite()!.config.server.host = host;\n }\n\n const server = (\n isHTTPS\n ? https.createServer(config.getVite()!.config.server.https!, app)\n : http.createServer(app)\n ).listen(port, host, () => {\n if (!isPrintInfo) {\n return;\n }\n\n void printServerInfo(config, { version, server });\n });\n\n return server;\n },\n app,\n };\n}\n\nexport default createServer;\n"],"names":["async","createServer","config","app","express","disable","setApp","isProd","root","publicDir","isSPA","getParams","use","compression","req","_","next","url","static","path","resolve","index","undefined","vite","import","server","middlewareMode","watch","usePolling","interval","appType","mode","middlewares","setVite","prepareServer","PrepareServer","init","res","html","loadHtml","join","send","e","onAppCreated","render","onRequest","renderParams","clientHtml","Promise","all","loadEntrypoint","appProps","hasEarlyHints","header","footer","context","run","version","isPrintInfo","port","host","isHTTPS","Boolean","getVite","https","isHost","http","listen","printServerInfo"],"mappings":"qNAoBAA,eAAeC,EAAaC,GAC1B,MAAMC,EAAMC,IAAUC,QAAQ,gBAI9B,GAFAH,EAAOI,OAAOH,GAETD,EAAOK,OAwBL,CACL,MAAMC,KAAEA,EAAIC,UAAEA,EAASC,MAAEA,GAAUR,EAAOS,YAE1CR,EAAIS,IAAIC,KAEHH,GAEHP,EAAIS,KAAI,CAACE,EAAKC,EAAGC,KACC,gBAAZF,EAAIG,MACNH,EAAIG,IAAM,yBAGZD,GAAM,IAIVb,EAAIS,IACFR,EAAQc,OAAOC,EAAKC,QAAQ,GAAGZ,KAAQC,KAAc,CACnDY,QAAOX,QAAQY,IAGpB,KA7CmB,CAIlB,MAAMC,cACEC,OAAO,SACbvB,aAAa,CACbwB,OAAQ,CACNC,gBAAgB,EAChBC,MAAO,CAGLC,YAAY,EACZC,SAAU,MAGdC,QAAS,SACTC,KAAM7B,EAAO6B,OAIf5B,EAAIS,IAAIW,EAAKS,aAEb9B,EAAO+B,QAAQV,EAChB,CAuBD,MAAMW,EAAgBC,EAAcC,KAAKlC,GA6CzC,OA1CKA,EAAOQ,MA6BVP,EAAIS,IAAI,KAAK,CAACE,EAAKuB,EAAKrB,KACjB,WACH,IACE,MAAMsB,SAAcJ,EAAcK,SAASzB,IAAM0B,KAAK,IAEtDH,EAAII,KAAKH,EACV,CAAC,MAAOI,GACP1B,EAAK0B,EACN,CACF,EARI,EAQD,WArCAR,EAAcS,eAEpBxC,EAAIS,IAAI,KAAK,CAACE,EAAKuB,EAAKrB,KACjB,WACH,IACE,OAAO4B,OAAEA,EAAMC,UAAEA,KAAcC,GAAgBC,SAAoBC,QAAQC,IAAI,CAC7Ef,EAAcgB,iBACdhB,EAAcK,SAASzB,MAEnBqC,SAAEA,EAAQC,cAAEA,SAAyBP,IAAY/B,EAAKuB,KAAS,IAC9DgB,EAAQC,GAAUP,EAEnBQ,EAA2B,CAC/BzC,MACAuB,MACAe,gBACAD,SAAUA,GAAY,CAAE,EACxBb,KAAM,CAAEe,SAAQC,iBAGZV,EAAO1C,EAAQqD,EAAST,EAC/B,CAAC,MAAOJ,GACP1B,EAAK0B,EACN,CACF,EArBI,EAqBD,KAiBD,CACLc,IAAK,EAAGC,UAASC,eAAc,GAAS,CAAA,KACtC,MAAMC,KAAEA,EAAIC,KAAEA,GAAS1D,EAAOS,YACxBkD,EAAUC,QAAQ5D,EAAO6D,WAAW7D,QAAQuB,QAAQuC,OAGtD9D,EAAO+D,SAAW/D,EAAOK,SAC3BL,EAAO6D,UAAW7D,OAAOuB,OAAOmC,KAAOA,GAGzC,MAAMnC,GACJoC,EACIG,EAAM/D,aAAaC,EAAO6D,UAAW7D,OAAOuB,OAAOuC,MAAQ7D,GAC3D+D,EAAKjE,aAAaE,IACtBgE,OAAOR,EAAMC,GAAM,KACdF,GAIAU,EAAgBlE,EAAQ,CAAEuD,UAAShC,UAAS,IAGnD,OAAOA,CAAM,EAEftB,MAEJ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lomray/vite-ssr-boost",
3
- "version": "2.3.0",
3
+ "version": "2.3.1",
4
4
  "description": "Vite plugin for create awesome SSR or SPA applications on React.",
5
5
  "type": "module",
6
6
  "keywords": [