@nuxt/nitro-server-nightly 4.3.0-29461891.8f4fbecd → 4.3.0-29466366.fa21bb17

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.
Files changed (63) hide show
  1. package/dist/index.d.mts +178 -80
  2. package/dist/index.mjs +664 -810
  3. package/dist/runtime/handlers/{error.d.ts → error.d.mts} +1 -1
  4. package/dist/runtime/handlers/error.mjs +77 -0
  5. package/dist/runtime/handlers/island.d.mts +2 -0
  6. package/dist/runtime/handlers/island.mjs +120 -0
  7. package/dist/runtime/handlers/renderer.d.mts +2 -0
  8. package/dist/runtime/handlers/renderer.mjs +298 -0
  9. package/dist/runtime/middleware/no-ssr.d.mts +2 -0
  10. package/dist/runtime/middleware/no-ssr.mjs +7 -0
  11. package/dist/runtime/plugins/dev-server-logs.d.mts +2 -0
  12. package/dist/runtime/plugins/dev-server-logs.mjs +94 -0
  13. package/dist/runtime/templates/error-500.mjs +15 -0
  14. package/dist/runtime/utils/app-config.d.mts +3 -0
  15. package/dist/runtime/utils/app-config.mjs +31 -0
  16. package/dist/runtime/utils/cache.d.mts +5 -0
  17. package/dist/runtime/utils/{cache.js → cache.mjs} +13 -12
  18. package/dist/runtime/utils/config.d.mts +1 -0
  19. package/dist/runtime/utils/{dev.d.ts → dev.d.mts} +1 -1
  20. package/dist/runtime/utils/{dev.js → dev.mjs} +15 -27
  21. package/dist/runtime/utils/error.d.mts +6 -0
  22. package/dist/runtime/utils/error.mjs +15 -0
  23. package/dist/runtime/utils/paths.mjs +19 -0
  24. package/dist/runtime/utils/renderer/{app.d.ts → app.d.mts} +4 -4
  25. package/dist/runtime/utils/renderer/app.mjs +39 -0
  26. package/dist/runtime/utils/renderer/build-files.d.mts +18 -0
  27. package/dist/runtime/utils/renderer/build-files.mjs +100 -0
  28. package/dist/runtime/utils/renderer/{inline-styles.d.ts → inline-styles.d.mts} +1 -1
  29. package/dist/runtime/utils/renderer/inline-styles.mjs +13 -0
  30. package/dist/runtime/utils/renderer/{islands.d.ts → islands.d.mts} +5 -5
  31. package/dist/runtime/utils/renderer/islands.mjs +87 -0
  32. package/dist/runtime/utils/renderer/payload.d.mts +24 -0
  33. package/dist/runtime/utils/renderer/payload.mjs +64 -0
  34. package/package.json +8 -8
  35. package/dist/index.d.ts +0 -87
  36. package/dist/runtime/handlers/error.js +0 -65
  37. package/dist/runtime/handlers/island.d.ts +0 -4
  38. package/dist/runtime/handlers/island.js +0 -101
  39. package/dist/runtime/handlers/renderer.d.ts +0 -2
  40. package/dist/runtime/handlers/renderer.js +0 -237
  41. package/dist/runtime/middleware/no-ssr.d.ts +0 -2
  42. package/dist/runtime/middleware/no-ssr.js +0 -7
  43. package/dist/runtime/plugins/dev-server-logs.d.ts +0 -3
  44. package/dist/runtime/plugins/dev-server-logs.js +0 -82
  45. package/dist/runtime/templates/error-500.js +0 -6
  46. package/dist/runtime/utils/app-config.d.ts +0 -3
  47. package/dist/runtime/utils/app-config.js +0 -25
  48. package/dist/runtime/utils/cache-driver.d.ts +0 -6
  49. package/dist/runtime/utils/cache.d.ts +0 -8
  50. package/dist/runtime/utils/config.d.ts +0 -1
  51. package/dist/runtime/utils/error.d.ts +0 -6
  52. package/dist/runtime/utils/error.js +0 -11
  53. package/dist/runtime/utils/paths.js +0 -16
  54. package/dist/runtime/utils/renderer/app.js +0 -34
  55. package/dist/runtime/utils/renderer/build-files.d.ts +0 -16
  56. package/dist/runtime/utils/renderer/build-files.js +0 -86
  57. package/dist/runtime/utils/renderer/inline-styles.js +0 -13
  58. package/dist/runtime/utils/renderer/islands.js +0 -82
  59. package/dist/runtime/utils/renderer/payload.d.ts +0 -24
  60. package/dist/runtime/utils/renderer/payload.js +0 -67
  61. /package/dist/runtime/templates/{error-500.d.ts → error-500.d.mts} +0 -0
  62. /package/dist/runtime/utils/{config.js → config.mjs} +0 -0
  63. /package/dist/runtime/utils/{paths.d.ts → paths.d.mts} +0 -0
@@ -1 +0,0 @@
1
- export declare const defineAppConfig: (config: any) => any;
@@ -1,6 +0,0 @@
1
- import type { H3Event } from 'h3';
2
- /**
3
- * Nitro internal functions extracted from https://github.com/nitrojs/nitro/blob/v2/src/runtime/internal/utils.ts
4
- */
5
- export declare function isJsonRequest(event: H3Event): boolean;
6
- export declare function hasReqHeader(event: H3Event, name: string, includes: string): boolean | "" | undefined;
@@ -1,11 +0,0 @@
1
- import { getRequestHeader } from "h3";
2
- export function isJsonRequest(event) {
3
- if (hasReqHeader(event, "accept", "text/html")) {
4
- return false;
5
- }
6
- return hasReqHeader(event, "accept", "application/json") || hasReqHeader(event, "user-agent", "curl/") || hasReqHeader(event, "user-agent", "httpie/") || hasReqHeader(event, "sec-fetch-mode", "cors") || event.path.startsWith("/api/") || event.path.endsWith(".json");
7
- }
8
- export function hasReqHeader(event, name, includes) {
9
- const value = getRequestHeader(event, name);
10
- return value && typeof value === "string" && value.toLowerCase().includes(includes);
11
- }
@@ -1,16 +0,0 @@
1
- import { joinRelativeURL } from "ufo";
2
- import { useRuntimeConfig } from "nitropack/runtime";
3
- export function baseURL() {
4
- return useRuntimeConfig().app.baseURL;
5
- }
6
- export function buildAssetsDir() {
7
- return useRuntimeConfig().app.buildAssetsDir;
8
- }
9
- export function buildAssetsURL(...path) {
10
- return joinRelativeURL(publicAssetsURL(), buildAssetsDir(), ...path);
11
- }
12
- export function publicAssetsURL(...path) {
13
- const app = useRuntimeConfig().app;
14
- const publicBase = app.cdnURL || app.baseURL;
15
- return path.length ? joinRelativeURL(publicBase, ...path) : publicBase;
16
- }
@@ -1,34 +0,0 @@
1
- import { decodePath } from "ufo";
2
- import { useRuntimeConfig } from "nitropack/runtime";
3
- import { createHead } from "@unhead/vue/server";
4
- import { sharedPrerenderCache } from "../cache.js";
5
- import unheadOptions from "#internal/unhead-options.mjs";
6
- import { NUXT_NO_SSR, NUXT_SHARED_DATA } from "#internal/nuxt/nitro-config.mjs";
7
- const PRERENDER_NO_SSR_ROUTES = /* @__PURE__ */ new Set(["/index.html", "/200.html", "/404.html"]);
8
- export function createSSRContext(event) {
9
- const ssrContext = {
10
- url: decodePath(event.path),
11
- event,
12
- runtimeConfig: useRuntimeConfig(event),
13
- noSSR: !!NUXT_NO_SSR || event.context.nuxt?.noSSR || (import.meta.prerender ? PRERENDER_NO_SSR_ROUTES.has(event.path) : false),
14
- head: createHead(unheadOptions),
15
- error: false,
16
- nuxt: void 0,
17
- /* NuxtApp */
18
- payload: {},
19
- ["~payloadReducers"]: /* @__PURE__ */ Object.create(null),
20
- modules: /* @__PURE__ */ new Set()
21
- };
22
- if (import.meta.prerender) {
23
- if (NUXT_SHARED_DATA) {
24
- ssrContext["~sharedPrerenderCache"] = sharedPrerenderCache;
25
- }
26
- ssrContext.payload.prerenderedAt = Date.now();
27
- }
28
- return ssrContext;
29
- }
30
- export function setSSRError(ssrContext, error) {
31
- ssrContext.error = true;
32
- ssrContext.payload = { error };
33
- ssrContext.url = error.url;
34
- }
@@ -1,16 +0,0 @@
1
- import type { RendererContext } from 'vue-bundle-renderer/runtime';
2
- import type { NuxtSSRContext } from 'nuxt/app';
3
- interface Renderer {
4
- rendererContext: RendererContext;
5
- renderToString(ssrContext: NuxtSSRContext): Promise<{
6
- html: string;
7
- renderResourceHeaders: () => Record<string, string>;
8
- renderResourceHints: () => string;
9
- renderStyles: () => string;
10
- renderScripts: () => string;
11
- }>;
12
- }
13
- export declare const getSSRRenderer: () => Promise<Renderer>;
14
- export declare function getRenderer(ssrContext: NuxtSSRContext): Promise<Renderer>;
15
- export declare const getSSRStyles: () => Promise<Record<string, () => Promise<string[]>>>;
16
- export {};
@@ -1,86 +0,0 @@
1
- import process from "node:process";
2
- import { createRenderer } from "vue-bundle-renderer/runtime";
3
- import { renderToString as _renderToString } from "vue/server-renderer";
4
- import { propsToString } from "@unhead/vue/server";
5
- import { useRuntimeConfig } from "nitropack/runtime";
6
- import { NUXT_NO_SSR } from "#internal/nuxt/nitro-config.mjs";
7
- import { appRootAttrs, appRootTag, appSpaLoaderAttrs, appSpaLoaderTag, spaLoadingTemplateOutside } from "#internal/nuxt.config.mjs";
8
- import { buildAssetsURL } from "#internal/nuxt/paths";
9
- const APP_ROOT_OPEN_TAG = `<${appRootTag}${propsToString(appRootAttrs)}>`;
10
- const APP_ROOT_CLOSE_TAG = `</${appRootTag}>`;
11
- const getServerEntry = () => import("#build/dist/server/server.mjs").then((r) => r.default || r);
12
- const getClientManifest = () => import("#build/dist/server/client.manifest.mjs").then((r) => r.default || r).then((r) => typeof r === "function" ? r() : r);
13
- const getPrecomputedDependencies = () => import("#build/dist/server/client.precomputed.mjs").then((r) => r.default || r).then((r) => typeof r === "function" ? r() : r);
14
- export const getSSRRenderer = lazyCachedFunction(async () => {
15
- const createSSRApp = await getServerEntry();
16
- if (!createSSRApp) {
17
- throw new Error("Server bundle is not available");
18
- }
19
- const precomputed = import.meta.dev ? void 0 : await getPrecomputedDependencies();
20
- const renderer = createRenderer(createSSRApp, {
21
- precomputed,
22
- manifest: import.meta.dev ? await getClientManifest() : void 0,
23
- renderToString,
24
- buildAssetsURL
25
- });
26
- async function renderToString(input, context) {
27
- const html = await _renderToString(input, context);
28
- if (import.meta.dev && process.env.NUXT_VITE_NODE_OPTIONS) {
29
- renderer.rendererContext.updateManifest(await getClientManifest());
30
- }
31
- return APP_ROOT_OPEN_TAG + html + APP_ROOT_CLOSE_TAG;
32
- }
33
- return renderer;
34
- });
35
- const getSPARenderer = lazyCachedFunction(async () => {
36
- const precomputed = import.meta.dev ? void 0 : await getPrecomputedDependencies();
37
- const spaTemplate = await import("#spa-template").then((r) => r.template).catch(() => "").then((r) => {
38
- if (spaLoadingTemplateOutside) {
39
- const APP_SPA_LOADER_OPEN_TAG = `<${appSpaLoaderTag}${propsToString(appSpaLoaderAttrs)}>`;
40
- const APP_SPA_LOADER_CLOSE_TAG = `</${appSpaLoaderTag}>`;
41
- const appTemplate = APP_ROOT_OPEN_TAG + APP_ROOT_CLOSE_TAG;
42
- const loaderTemplate = r ? APP_SPA_LOADER_OPEN_TAG + r + APP_SPA_LOADER_CLOSE_TAG : "";
43
- return appTemplate + loaderTemplate;
44
- } else {
45
- return APP_ROOT_OPEN_TAG + r + APP_ROOT_CLOSE_TAG;
46
- }
47
- });
48
- const renderer = createRenderer(() => () => {
49
- }, {
50
- precomputed,
51
- manifest: import.meta.dev ? await getClientManifest() : void 0,
52
- renderToString: () => spaTemplate,
53
- buildAssetsURL
54
- });
55
- const result = await renderer.renderToString({});
56
- const renderToString = (ssrContext) => {
57
- const config = useRuntimeConfig(ssrContext.event);
58
- ssrContext.modules ||= /* @__PURE__ */ new Set();
59
- ssrContext.payload.serverRendered = false;
60
- ssrContext.config = {
61
- public: config.public,
62
- app: config.app
63
- };
64
- return Promise.resolve(result);
65
- };
66
- return {
67
- rendererContext: renderer.rendererContext,
68
- renderToString
69
- };
70
- });
71
- function lazyCachedFunction(fn) {
72
- let res = null;
73
- return () => {
74
- if (res === null) {
75
- res = fn().catch((err) => {
76
- res = null;
77
- throw err;
78
- });
79
- }
80
- return res;
81
- };
82
- }
83
- export function getRenderer(ssrContext) {
84
- return NUXT_NO_SSR || ssrContext.noSSR ? getSPARenderer() : getSSRRenderer();
85
- }
86
- export const getSSRStyles = lazyCachedFunction(() => import("#build/dist/server/styles.mjs").then((r) => r.default || r));
@@ -1,13 +0,0 @@
1
- import { getSSRStyles } from "./build-files.js";
2
- export async function renderInlineStyles(usedModules) {
3
- const styleMap = await getSSRStyles();
4
- const inlinedStyles = /* @__PURE__ */ new Set();
5
- for (const mod of usedModules) {
6
- if (mod in styleMap && styleMap[mod]) {
7
- for (const style of await styleMap[mod]()) {
8
- inlinedStyles.add(style);
9
- }
10
- }
11
- }
12
- return Array.from(inlinedStyles).map((style) => ({ innerHTML: style }));
13
- }
@@ -1,82 +0,0 @@
1
- import { appRootTag } from "#internal/nuxt.config.mjs";
2
- const ROOT_NODE_REGEX = new RegExp(`^<${appRootTag}[^>]*>([\\s\\S]*)<\\/${appRootTag}>$`);
3
- export function getServerComponentHTML(body) {
4
- const match = body.match(ROOT_NODE_REGEX);
5
- return match?.[1] || body;
6
- }
7
- const SSR_SLOT_TELEPORT_MARKER = /^uid=([^;]*);slot=(.*)$/;
8
- const SSR_CLIENT_TELEPORT_MARKER = /^uid=([^;]*);client=(.*)$/;
9
- const SSR_CLIENT_SLOT_MARKER = /^island-slot=([^;]*);(.*)$/;
10
- export function getSlotIslandResponse(ssrContext) {
11
- if (!ssrContext.islandContext || !Object.keys(ssrContext.islandContext.slots).length) {
12
- return void 0;
13
- }
14
- const response = {};
15
- for (const [name, slot] of Object.entries(ssrContext.islandContext.slots)) {
16
- response[name] = {
17
- ...slot,
18
- fallback: ssrContext.teleports?.[`island-fallback=${name}`]
19
- };
20
- }
21
- return response;
22
- }
23
- export function getClientIslandResponse(ssrContext) {
24
- if (!ssrContext.islandContext || !Object.keys(ssrContext.islandContext.components).length) {
25
- return void 0;
26
- }
27
- const response = {};
28
- for (const [clientUid, component] of Object.entries(ssrContext.islandContext.components)) {
29
- const html = ssrContext.teleports?.[clientUid]?.replaceAll("<!--teleport start anchor-->", "") || "";
30
- response[clientUid] = {
31
- ...component,
32
- html,
33
- slots: getComponentSlotTeleport(clientUid, ssrContext.teleports ?? {})
34
- };
35
- }
36
- return response;
37
- }
38
- export function getComponentSlotTeleport(clientUid, teleports) {
39
- const entries = Object.entries(teleports);
40
- const slots = {};
41
- for (const [key, value] of entries) {
42
- const match = key.match(SSR_CLIENT_SLOT_MARKER);
43
- if (match) {
44
- const [, id, slot] = match;
45
- if (!slot || clientUid !== id) {
46
- continue;
47
- }
48
- slots[slot] = value;
49
- }
50
- }
51
- return slots;
52
- }
53
- export function replaceIslandTeleports(ssrContext, html) {
54
- const { teleports, islandContext } = ssrContext;
55
- if (islandContext || !teleports) {
56
- return html;
57
- }
58
- for (const key in teleports) {
59
- const matchClientComp = key.match(SSR_CLIENT_TELEPORT_MARKER);
60
- if (matchClientComp) {
61
- const [, uid, clientId] = matchClientComp;
62
- if (!uid || !clientId) {
63
- continue;
64
- }
65
- html = html.replace(new RegExp(` data-island-uid="${uid}" data-island-component="${clientId}"[^>]*>`), (full) => {
66
- return full + teleports[key];
67
- });
68
- continue;
69
- }
70
- const matchSlot = key.match(SSR_SLOT_TELEPORT_MARKER);
71
- if (matchSlot) {
72
- const [, uid, slot] = matchSlot;
73
- if (!uid || !slot) {
74
- continue;
75
- }
76
- html = html.replace(new RegExp(` data-island-uid="${uid}" data-island-slot="${slot}"[^>]*>`), (full) => {
77
- return full + teleports[key];
78
- });
79
- }
80
- }
81
- return html;
82
- }
@@ -1,24 +0,0 @@
1
- import type { NitroRouteRules, RenderResponse } from 'nitropack/types';
2
- import type { Script } from '@unhead/vue';
3
- import type { NuxtPayload, NuxtSSRContext } from 'nuxt/app';
4
- export declare function renderPayloadResponse(ssrContext: NuxtSSRContext): RenderResponse;
5
- export declare function renderPayloadJsonScript(opts: {
6
- ssrContext: NuxtSSRContext;
7
- data?: any;
8
- src?: string;
9
- }): Script[];
10
- export declare function renderPayloadScript(opts: {
11
- ssrContext: NuxtSSRContext;
12
- routeOptions: NitroRouteRules;
13
- data?: any;
14
- src?: string;
15
- }): Script[];
16
- interface SplitPayload {
17
- initial: Omit<NuxtPayload, 'data'>;
18
- payload: {
19
- data?: NuxtPayload['data'];
20
- prerenderedAt?: NuxtPayload['prerenderedAt'];
21
- };
22
- }
23
- export declare function splitPayload(ssrContext: NuxtSSRContext): SplitPayload;
24
- export {};
@@ -1,67 +0,0 @@
1
- import { getResponseStatus, getResponseStatusText } from "h3";
2
- import devalue from "@nuxt/devalue";
3
- import { stringify, uneval } from "devalue";
4
- import { appId, multiApp } from "#internal/nuxt.config.mjs";
5
- import { NUXT_JSON_PAYLOADS, NUXT_NO_SSR, NUXT_PAYLOAD_EXTRACTION, NUXT_RUNTIME_PAYLOAD_EXTRACTION } from "#internal/nuxt/nitro-config.mjs";
6
- export function renderPayloadResponse(ssrContext) {
7
- return {
8
- body: NUXT_JSON_PAYLOADS ? stringify(splitPayload(ssrContext).payload, ssrContext["~payloadReducers"]) : `export default ${devalue(splitPayload(ssrContext).payload)}`,
9
- statusCode: getResponseStatus(ssrContext.event),
10
- statusMessage: getResponseStatusText(ssrContext.event),
11
- headers: {
12
- "content-type": NUXT_JSON_PAYLOADS ? "application/json;charset=utf-8" : "text/javascript;charset=utf-8",
13
- "x-powered-by": "Nuxt"
14
- }
15
- };
16
- }
17
- export function renderPayloadJsonScript(opts) {
18
- const contents = opts.data ? stringify(opts.data, opts.ssrContext["~payloadReducers"]) : "";
19
- const payload = {
20
- "type": "application/json",
21
- "innerHTML": contents,
22
- "data-nuxt-data": appId,
23
- "data-ssr": !(NUXT_NO_SSR || opts.ssrContext.noSSR)
24
- };
25
- if (!multiApp) {
26
- payload.id = "__NUXT_DATA__";
27
- }
28
- if (opts.src) {
29
- payload["data-src"] = opts.src;
30
- }
31
- const config = uneval(opts.ssrContext.config);
32
- return [
33
- payload,
34
- {
35
- innerHTML: multiApp ? `window.__NUXT__=window.__NUXT__||{};window.__NUXT__[${JSON.stringify(appId)}]={config:${config}}` : `window.__NUXT__={};window.__NUXT__.config=${config}`
36
- }
37
- ];
38
- }
39
- export function renderPayloadScript(opts) {
40
- opts.data.config = opts.ssrContext.config;
41
- const _PAYLOAD_EXTRACTION = !opts.ssrContext.noSSR && (import.meta.prerender && NUXT_PAYLOAD_EXTRACTION || NUXT_RUNTIME_PAYLOAD_EXTRACTION && (opts.routeOptions.isr || opts.routeOptions.cache));
42
- const nuxtData = devalue(opts.data);
43
- if (_PAYLOAD_EXTRACTION) {
44
- const singleAppPayload2 = `import p from "${opts.src}";window.__NUXT__={...p,...(${nuxtData})}`;
45
- const multiAppPayload2 = `import p from "${opts.src}";window.__NUXT__=window.__NUXT__||{};window.__NUXT__[${JSON.stringify(appId)}]={...p,...(${nuxtData})}`;
46
- return [
47
- {
48
- type: "module",
49
- innerHTML: multiApp ? multiAppPayload2 : singleAppPayload2
50
- }
51
- ];
52
- }
53
- const singleAppPayload = `window.__NUXT__=${nuxtData}`;
54
- const multiAppPayload = `window.__NUXT__=window.__NUXT__||{};window.__NUXT__[${JSON.stringify(appId)}]=${nuxtData}`;
55
- return [
56
- {
57
- innerHTML: multiApp ? multiAppPayload : singleAppPayload
58
- }
59
- ];
60
- }
61
- export function splitPayload(ssrContext) {
62
- const { data, prerenderedAt, ...initial } = ssrContext.payload;
63
- return {
64
- initial: { ...initial, prerenderedAt },
65
- payload: { data, prerenderedAt }
66
- };
67
- }
File without changes
File without changes