vike-lite 1.13.1 → 1.13.2

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.
@@ -122,7 +122,6 @@ async function renderErrorPage(req, status, urlPathname, error, nonce) {
122
122
  } else is500 = false;
123
123
  if (!store.errorRoute) return new Response(status === 404 ? "Not Found" : "Internal Server Error", { status });
124
124
  try {
125
- const { default: onRenderHtml } = await store.config.onRenderHtml();
126
125
  const [PageModule, HeadModule, LayoutModule] = await Promise.all([
127
126
  store.errorRoute.Page(),
128
127
  store.errorRoute.Head?.() ?? null,
@@ -136,7 +135,7 @@ async function renderErrorPage(req, status, urlPathname, error, nonce) {
136
135
  is500,
137
136
  errorMessage
138
137
  };
139
- const html = await onRenderHtml({
138
+ const html = await store.config.onRenderHtml({
140
139
  pageContext,
141
140
  Page: PageModule.Page ?? PageModule.default,
142
141
  Layout: LayoutModule ? LayoutModule.Layout ?? LayoutModule.default : void 0,
@@ -177,8 +176,7 @@ async function renderPage(req, { nonce } = {}) {
177
176
  }
178
177
  const { pageContext, route, PageModule, HeadModule, LayoutModule } = resolved;
179
178
  if (isJsonRequest) return Response.json(pageContext);
180
- const { default: onRenderHtml } = await store.config.onRenderHtml();
181
- const html = await onRenderHtml({
179
+ const html = await store.config.onRenderHtml({
182
180
  pageContext,
183
181
  Page: PageModule.Page ?? PageModule.default,
184
182
  Head: HeadModule ? HeadModule.Head ?? HeadModule.default : void 0,
package/dist/server.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { t as renderPage } from "./server-Cm1ZA_Dp.mjs";
1
+ import { t as renderPage } from "./server-GrGbl23a.mjs";
2
2
  export { renderPage };
package/dist/vite.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Plugin } from "vite";
2
- //#region src/vite-plugin.d.ts
2
+ //#region src/vite/index.d.ts
3
3
  declare function routerPlugin({ pagesDir, serverEntry, apiPrefix, prerender }?: {
4
4
  /**
5
5
  * The directory where your page components are located.
package/dist/vite.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { t as renderPage } from "./server-Cm1ZA_Dp.mjs";
1
+ import { t as renderPage } from "./server-GrGbl23a.mjs";
2
2
  import fs from "node:fs";
3
3
  import path from "node:path";
4
4
  import { Readable } from "node:stream";
@@ -98,7 +98,7 @@ async function injectFOUCStyles(server, html) {
98
98
  //#region src/config.ts
99
99
  const SUPPORTED_RENDERERS = ["solid"];
100
100
  //#endregion
101
- //#region src/vite-plugin.ts
101
+ //#region src/vite/index.ts
102
102
  function routerPlugin({ pagesDir = "pages", serverEntry = "server/index", apiPrefix = "/api", prerender = false } = {}) {
103
103
  const isProd = process.env.NODE_ENV === "production";
104
104
  let viteConfigRoot;
@@ -107,7 +107,8 @@ function routerPlugin({ pagesDir = "pages", serverEntry = "server/index", apiPre
107
107
  const VIRTUAL = {
108
108
  routes: "virtual:routes",
109
109
  manifest: "virtual:client-manifest",
110
- renderer: "virtual:vike-lite/renderer",
110
+ client: "virtual:vike-lite/client",
111
+ server: "virtual:vike-lite/server",
111
112
  entryClient: "virtual:entry-client",
112
113
  setup: "virtual:vike-lite/setup",
113
114
  entryServer: "virtual:entry-server",
@@ -216,7 +217,7 @@ function routerPlugin({ pagesDir = "pages", serverEntry = "server/index", apiPre
216
217
  if (id === RESOLVED.routes) {
217
218
  const { routes, errorRoute } = generateRoutes(viteConfigRoot, pagesDir);
218
219
  const isSSR = options.ssr;
219
- let code = `import { onRenderHtml } from '${VIRTUAL.renderer}';\nexport const config = { onRenderHtml };\nexport const routes = [\n`;
220
+ let code = `import { onRenderHtml } from '${VIRTUAL.server}';\nexport const config = { onRenderHtml };\nexport const routes = [\n`;
220
221
  for (const r of routes) {
221
222
  code += `{path:'${r.path}',page:'${r.page}',Page:()=>import('/${r.page}'),`;
222
223
  if (r.head) code += `head:'${r.head}',Head:()=>import('/${r.head}'),`;
@@ -246,7 +247,7 @@ function routerPlugin({ pagesDir = "pages", serverEntry = "server/index", apiPre
246
247
  const manifestPath = path.join(viteConfigRoot, outDir, "client/.vite/manifest.json");
247
248
  return `export default ${fs.readFileSync(manifestPath, "utf8")}`;
248
249
  }
249
- if (id === RESOLVED.entryClient) return `import{routes,errorRoute}from'${VIRTUAL.routes}';import{onRenderClient}from'${VIRTUAL.renderer}';const{default:render}=await onRenderClient();await render({routes,errorRoute});`;
250
+ if (id === RESOLVED.entryClient) return `import{routes,errorRoute}from'${VIRTUAL.routes}';import{onRenderClient}from'${VIRTUAL.client}';await (await onRenderClient()).default({routes,errorRoute});`;
250
251
  if (id === RESOLVED.setup) return `import{routes,errorRoute,config}from'${VIRTUAL.routes}';import{setVikeState}from'vike-lite/__internal/server';const manifest=process.env.NODE_ENV==='production'?(await import('${VIRTUAL.manifest}')).default:null;setVikeState({routes,errorRoute,config,manifest});`;
251
252
  if (id === RESOLVED.entryServer) {
252
253
  if (serverEntry) {
@@ -263,94 +264,8 @@ function routerPlugin({ pagesDir = "pages", serverEntry = "server/index", apiPre
263
264
  if (!serverEntryPath) throw new Error(`[vike-lite] serverEntry ${serverEntry} file not found`);
264
265
  return `import '${VIRTUAL.setup}';export * from'${serverEntryPath}';export{default}from'${serverEntryPath}';`;
265
266
  }
266
- return `import '${VIRTUAL.setup}';import{renderPage}from'vike-lite/server';
267
- export default{async fetch(request){return renderPage(request);}};
268
- if (process.env.NODE_ENV === 'production') {
269
- const { createServer } = await import('node:http');
270
- const { Readable } = await import('node:stream');
271
- const { pipeline } = await import('node:stream/promises');
272
- const fs = await import('node:fs');
273
- const path = await import('node:path');
274
- const { fileURLToPath } = await import('node:url');
275
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
276
- const clientDir = path.resolve(__dirname, '../client');
277
- const MIME_TYPES = {
278
- '.html': 'text/html; charset=utf-8',
279
- '.js': 'text/javascript; charset=utf-8',
280
- '.mjs': 'text/javascript; charset=utf-8',
281
- '.css': 'text/css; charset=utf-8',
282
- '.json': 'application/json; charset=utf-8',
283
- '.xml': 'application/xml',
284
- '.txt': 'text/plain; charset=utf-8',
285
- '.map': 'application/json; charset=utf-8',
286
- '.png': 'image/png',
287
- '.jpg': 'image/jpeg',
288
- '.jpeg': 'image/jpeg',
289
- '.gif': 'image/gif',
290
- '.svg': 'image/svg+xml',
291
- '.ico': 'image/x-icon',
292
- '.webp': 'image/webp',
293
- '.avif': 'image/avif',
294
- '.woff': 'font/woff',
295
- '.woff2': 'font/woff2',
296
- '.ttf': 'font/ttf',
297
- '.otf': 'font/otf',
298
- '.mp4': 'video/mp4',
299
- '.webm': 'video/webm',
300
- '.mp3': 'audio/mpeg',
301
- '.pdf': 'application/pdf',
302
- '.wasm': 'application/wasm',
303
- '.webmanifest': 'application/manifest+json'
304
- };
305
- const { BASE_URL } = import.meta.env;
306
- const server = createServer(async (req, res) => {
307
- try {
308
- const urlObj = new URL(req.url || '/', 'http://' + (req.headers.host || 'localhost'));
309
- const pathname = urlObj.pathname;
310
- let fileUrl = pathname;
311
- if (BASE_URL !== '/' && pathname.startsWith(BASE_URL)) fileUrl = '/' + pathname.slice(BASE_URL.length);
312
- if (fileUrl !== '/') {
313
- const filePath = path.resolve(clientDir, '.' + fileUrl)
314
- if (!filePath.startsWith(clientDir + path.sep)) {
315
- res.statusCode = 403
316
- res.end('Forbidden')
317
- return
318
- }
319
- if (filePath.startsWith(clientDir) && fs.existsSync(filePath) && fs.statSync(filePath).isFile()) {
320
- const ext = path.extname(filePath).toLowerCase();
321
- const mimeType = MIME_TYPES[ext] || 'application/octet-stream';
322
- res.setHeader('Content-Type', mimeType);
323
- res.setHeader('Cache-Control', fileUrl.startsWith('/assets/') ? 'public, max-age=31536000, immutable' : 'public, max-age=0, must-revalidate')
324
- fs.createReadStream(filePath).pipe(res);
325
- return;
326
- }
327
- }
328
- const headers = new Headers();
329
- for (const [key, val] of Object.entries(req.headers)) {
330
- if (Array.isArray(val)) val.forEach(v => headers.append(key, v));
331
- else if (val) headers.set(key, val);
332
- }
333
- const { method } = req;
334
- const init = { method, headers };
335
- if (method !== 'GET' && method !== 'HEAD') { init.body = Readable.toWeb(req); init.duplex = 'half'; }
336
- const request = new Request(urlObj.href, init);
337
- const response = await renderPage(request);
338
- res.statusCode = response.status;
339
- for (const [key, val] of response.headers) res.setHeader(key, val);
340
- if (method === 'HEAD' || !response.body) { await response.body?.cancel(); res.end(); return; }
341
- try { await pipeline(Readable.fromWeb(response.body), res); } catch {}
342
- } catch (e) {
343
- console.error(e);
344
- res.statusCode = 500;
345
- res.end('Internal Server Error');
346
- }
347
- });
348
- const { PORT } = process.env;
349
- const port = PORT ? Number.parseInt(PORT) : 3000;
350
- server.listen(port, () => {
351
- console.log('\n\u{1B}[32m🚀 Server is running at http://localhost:' + port + '\u{1B}[0m\n');
352
- });
353
- }`;
267
+ const defaultServerEntry = fs.readFileSync(path.resolve(viteConfigRoot, "defaultServerEntry.mjs"), "utf8");
268
+ return `import '${VIRTUAL.setup}';` + defaultServerEntry;
354
269
  }
355
270
  if (id === RESOLVED.entryPrerender) return `import'${VIRTUAL.setup}';export{routes}from'${VIRTUAL.routes}';`;
356
271
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike-lite",
3
- "version": "1.13.1",
3
+ "version": "1.13.2",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "./dist/index.mjs",