import { j as joinRelativeURL, u as useRuntimeConfig, g as appRootTag, h as appRootAttrs, i as appSpaLoaderTag, k as appSpaLoaderAttrs, w as writeEarlyHints, e as createError, b as useNitroApp, l as getRouteRules, m as createHead, N as NUXT_PRERENDER_NO_SSR_ROUTES, n as unheadOptions, o as appId, p as getQuery, q as appHead, d as destr, v as NUXT_SSR_STREAMING, x as renderSSRHeadOptions, y as appTeleportAttrs, z as NUXT_NO_SCRIPTS_PATTERNS, A as relative, B as joinURL, C as appTeleportTag, D as NUXT_PAGE_PATTERNS, E as defineRenderHandler, F as toRequestEvent, G as setResponseHeader } from '../_/nitro.mjs'; import { defineDiagnostics, createConsoleReporter } from 'nostics'; import { renderToString } from 'vue/server-renderer'; import { createRenderer, getRequestDependencies, getPreloadLinks, getPrefetchLinks } from 'vue-bundle-renderer/runtime'; import { propsToString, renderSSRHead } from 'unhead/server'; import { stringify, uneval } from 'devalue'; //#region src/runtime/utils/paths.ts function baseURL() { return useRuntimeConfig().app.baseURL; } function buildAssetsDir() { return useRuntimeConfig().app.buildAssetsDir; } function buildAssetsURL(...path) { return joinRelativeURL(publicAssetsURL(), buildAssetsDir(), ...path); } function publicAssetsURL(...path) { const app = useRuntimeConfig().app; const publicBase = app.cdnURL || app.baseURL; return path.length ? joinRelativeURL(publicBase, ...path) : publicBase; } //#region src/runtime/utils/response.ts /** * The response the renderer builds, keeping its body as the renderer produced it. * * A real `Response` turns every body into a `ReadableStream`, which would send a rendered * document as a chunked stream where nitro sends the string it was given. The renderer only * reads the fields below back, so this describes just those. */ var NodeRenderResponse = class { body; status; statusText; headers; constructor(body, init) { this.body = body; this.status = init?.status || 200; this.statusText = init?.statusText || ""; this.headers = init?.headers instanceof Headers ? init.headers : new Headers(init?.headers); } }; //#region src/runtime/server/renderer/cache.ts function lazyCachedFunction(fn) { let res = null; return () => { if (res === null) res = fn().catch((err) => { res = null; throw err; }); return res; }; } /** * E8xxx * SSR rendering diagnostics, sharing the range with the server runtime that * hosts the renderer. */ const docsBase = (code) => `https://nuxt.com/docs/4.x/errors/${code.replace("NUXT_", "").toLowerCase()}`; const rendererDiagnostics = /* #__PURE__ */ defineDiagnostics({ docsBase, reporters: [/* @__PURE__ */ createConsoleReporter(void 0)], codes: { NUXT_E8001: { why: (p) => `\`render:html\` mutated \`body\`/\`bodyAppend\` while streaming (\`${p.path}\`). These fields are silently dropped because the body is about to stream.`, fix: "Use the `render:html:close` hook instead.", docs: false }, NUXT_E8002: { why: (p) => `SSR streaming committed the response before render completed (\`${p.path}\`). The following mutations did not reach the client and were dropped:\n - ${p.mutations}`, fix: (p) => `Move the mutation into a plugin (which runs before the shell is flushed), or opt this route out of streaming with \`routeRules: { '${p.path}': { streaming: false } }\` or the \`render:route\` hook.`, docs: false }, NUXT_E8004: { why: "The server bundle is not available.", fix: "Ensure the Nuxt build completed successfully and the server entry was emitted by your builder.", docs: false }, NUXT_E8006: { why: (p) => `The payload for \`${p.path}\` is ${p.size}, which will increase the page size and slow down hydration.${p.keys ? ` Largest payload keys:\n - ${p.keys}` : ""}`, fix: "Use the `pick` or `transform` options of `useAsyncData`/`useFetch` to strip out data the client does not need.", docs: false }, NUXT_E8007: { why: (p) => `\`${p.path}\` relies on client-side JavaScript, but \`features.noScripts: 'production'\` will strip scripts from this route in production:\n - ${p.reasons}`, fix: "Remove the client-side dependency from this route, or scope script stripping with the `noScripts` route rule instead of enabling it globally." }, NUXT_E8009: { why: (p) => `A page error interrupted the stream for \`${p.path}\`, and ${p.what} also failed while rendering the error response.\n ${p.cause}`, fix: "Fix the page error first. If it keeps happening, report the failure below - the browser will show a blank or partial page instead of the error page." } } }); //#region src/runtime/server/renderer/build-files.ts const APP_ROOT_OPEN_TAG = `<${appRootTag}${propsToString(appRootAttrs)}>`; const APP_ROOT_CLOSE_TAG = ``; const getServerEntry = () => import('../virtual/entry.mjs').then(function (n) { return n.g; }).then((r) => r.default || r); const getPrecomputedDependencies = () => import('../virtual/precomputed.mjs').then((r) => "default" in r ? r.default : r).then((r) => typeof r === "function" ? r() : r); /** Load the build artifacts for a set of renderer options, caching each of them on the returned object. */ function createBuildFiles(options) { const buildAssetsURL = (...path) => options.buildAssetsURL(...path); const getSSRRenderer = lazyCachedFunction(async () => { const createSSRApp = await getServerEntry(); if (!createSSRApp) throw rendererDiagnostics.NUXT_E8004(); const precomputed = await getPrecomputedDependencies(); const renderer = createRenderer(createSSRApp, { precomputed, manifest: void 0, renderToString: renderToString$1, buildAssetsURL }); async function renderToString$1(input, context) { const html = await renderToString(input, context); return APP_ROOT_OPEN_TAG + html + APP_ROOT_CLOSE_TAG; } return renderer; }); const getSPARenderer = lazyCachedFunction(async () => { const precomputed = await getPrecomputedDependencies(); const template = renderSPATemplate(); const renderer = createRenderer(() => () => {}, { precomputed, manifest: void 0, renderToString: () => template, buildAssetsURL }); const result = await renderer.renderToString({}); const renderToString = (ssrContext) => { const config = ssrContext.runtimeConfig; ssrContext.modules ||= /* @__PURE__ */ new Set(); ssrContext.payload.serverRendered = false; ssrContext.config = { public: config.public, app: config.app }; return Promise.resolve(result); }; return { rendererContext: renderer.rendererContext, renderToString }; }); return { getRenderer: (ssrContext) => ssrContext.noSSR ? getSPARenderer() : getSSRRenderer(), getSSRRenderer, getServerApp: lazyCachedFunction(getServerEntry) }; } function renderSPATemplate() { { `<${appSpaLoaderTag}${propsToString(appSpaLoaderAttrs)}>`; return APP_ROOT_OPEN_TAG + APP_ROOT_CLOSE_TAG + (""); } } const getSSRStyles = lazyCachedFunction(() => import('../virtual/styles.mjs').then((r) => r.default || r)); const getInlinedCSS = lazyCachedFunction(() => import('../virtual/styles.mjs').then((r) => r.inlinedCSS || {})); //#region src/runtime/server/renderer/instance.ts /** * Create the renderer state for a set of options. * * Called by `createNuxtRenderer()`; call it directly only to render against the same * artifacts as a renderer created elsewhere (an island handler sharing the server bundle * loaded for page renders), and pass the result to `createNuxtRenderer()`. */ function createRendererInstance(options) { return { options, ...createBuildFiles(options) }; } //#region src/runtime/server/renderer/runtime.ts /** The event to pass to application code and to the render hooks. */ function appEvent(event) { return event["~app"] ?? event; } function getRequestState(event) { return event.context.nuxt; } //#region src/runtime/utils/renderer/options.ts globalThis.__buildAssetsURL = buildAssetsURL; globalThis.__publicAssetsURL = publicAssetsURL; /** The capabilities a nitropack v2 host provides to the Nuxt renderer. */ const rendererOptions = { runtimeConfig: (event) => useRuntimeConfig(appEvent(event)), buildAssetsURL, publicAssetsURL, getRouteRules: (event) => getRouteRules(appEvent(event)), hooks: () => useNitroApp().hooks, createResponse: (body, init) => new NodeRenderResponse(body, init), createError: (init) => createError({ statusCode: init.status, statusMessage: init.statusText, message: init.statusText, data: init.data }), writeEarlyHints: (event, hints) => writeEarlyHints(appEvent(event), hints.link), onRenderSuccess: void 0, prerender: void 0 }; /** * The renderer the page and island handlers share, so that both render against a single * load of the server bundle and its manifest. */ const rendererInstance = createRendererInstance(rendererOptions); //#region src/runtime/server/renderer/url.ts /** * The fragment of a request URL, avoiding the lazy URL parse that reading `hash` triggers when * there is none. A fragment is never sent over the wire, so it can only appear on a URL the * server constructed itself. */ function urlHash(url) { return url.href.includes("#") ? url.hash : ""; } //#region src/runtime/server/renderer/app.ts new Set(NUXT_PRERENDER_NO_SSR_ROUTES); function createServerHead() { return createHead(unheadOptions); } function createSSRContext(options, event) { const url = event.url.pathname + event.url.search + urlHash(event.url); const ssrContext = { url, event: appEvent(event), runtimeConfig: options.runtimeConfig(event), noSSR: getRequestState(event)?.noSSR || (false), head: createServerHead(), error: false, nuxt: void 0, payload: {}, ["~payloadReducers"]: Object.create(null), modules: /* @__PURE__ */ new Set() }; return ssrContext; } /** * Turn the response the renderer assembled into a web-standard `Response`, carrying the * headers queued on the event alongside the ones the response names for itself. */ function returnRenderResponse(options, event, response) { const headers = new Headers(event.res.headers); for (const name in response.headers) headers.set(name, response.headers[name]); return options.createResponse(response.body ?? null, { status: response.statusCode ?? event.res.status, statusText: response.statusMessage ?? event.res.statusText, headers }); } function setSSRError(ssrContext, error) { ssrContext.error = true; ssrContext.payload = { error }; ssrContext.url = error.url; } function renderPayloadJsonScript(opts) { const contents = opts.data ? encodeForwardSlashes(stringify(opts.data, opts.ssrContext["~payloadReducers"])) : ""; const payload = { "type": "application/json", "innerHTML": contents, "data-nuxt-data": appId, "data-ssr": !(opts.ssrContext.noSSR) }; payload.id = "__NUXT_DATA__"; if (opts.src) payload["data-src"] = opts.src; const config = uneval(opts.ssrContext.config); return [payload, { innerHTML: `window.__NUXT__={};window.__NUXT__.config=${config}` }]; } /** * Encode forward slashes as unicode escape sequences to prevent * Google from treating them as internal links and trying to crawl them. * @see https://github.com/nuxt/nuxt/issues/24175 */ function encodeForwardSlashes(str) { return str.replaceAll("/", "\\u002F"); } //#region src/runtime/server/renderer/inline-styles.ts async function renderInlineStyles(usedModules) { const styleMap = await getSSRStyles(); const inlinedStyles = /* @__PURE__ */ new Set(); const promises = []; for (const mod of usedModules) if (mod in styleMap && styleMap[mod]) promises.push(styleMap[mod]()); for (const styles of await Promise.all(promises)) for (const style of styles) inlinedStyles.add(style); return Array.from(inlinedStyles).map((style) => ({ innerHTML: style })); } //#region src/runtime/server/renderer/inlined-css.ts /** * Build a predicate telling whether the contents of an emitted CSS file were * inlined as `