import { j as joinRelativeURL, u as useRuntimeConfig, i as appRootTag, k as appRootAttrs, l as appSpaLoaderTag, m as appSpaLoaderAttrs, w as writeEarlyHints, e as createError, b as useNitroApp, n as getRouteRules, o as createHead, N as NUXT_PRERENDER_NO_SSR_ROUTES, p as unheadOptions, q as appId, r as getQuery, v as appHead, d as destr, x as NUXT_SSR_STREAMING, y as renderSSRHeadOptions, z as appTeleportAttrs, A as NUXT_NO_SCRIPTS_PATTERNS, B as relative, C as joinURL, D as NUXT_PAYLOAD_INLINE, E as appTeleportTag, F as NUXT_PAGE_PATTERNS, G as defineRenderHandler, H as toRequestEvent, I 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/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); } }; /** * The headers of a node response as the record nitro's `render:response` hook passes, * read from and written to the node response itself. `set-cookie` is omitted, as it * cannot be represented as one string. The proxy target is kept as a snapshot for * `util.inspect`, which bypasses the traps. */ function createResponseHeaderRecord(res) { const read = (name) => { if (typeof name !== "string" || name.toLowerCase() === "set-cookie") return; const value = res.getHeader(name); if (value === void 0) return; return Array.isArray(value) ? value.join(", ") : String(value); }; const snapshot = {}; const sync = (name) => { const value = read(name); if (value === void 0) delete snapshot[name.toLowerCase()]; else snapshot[name.toLowerCase()] = value; }; for (const name of res.getHeaderNames()) sync(name); return new Proxy(snapshot, { get: (_, name) => read(name), has: (_, name) => read(name) !== void 0, set(_, name, value) { if (typeof name === "string") { if (value === void 0 || value === null) res.removeHeader(name); else res.setHeader(name, value); sync(name); } return true; }, deleteProperty(_, name) { if (typeof name === "string") { res.removeHeader(name); sync(name); } return true; }, ownKeys: () => res.getHeaderNames().filter((name) => name !== "set-cookie"), getOwnPropertyDescriptor(_, name) { const value = read(name); return value === void 0 ? void 0 : { value, writable: true, enumerable: true, configurable: true }; } }); } //#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/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.aj; }).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 : ""; } const PAYLOAD_BUILD_ID_PARAM = "_b"; /** Parse a request path without treating a leading `//` as an authority. */ function parseRequestPath(path) { return new URL("http://localhost" + path); } /** The page route a `_payload.json` (or `_payload.js`) request renders, without the build id param. */ function payloadRequestToRoute(path, filename = "_payload.json") { const payloadURL = parseRequestPath(path); const url = payloadURL.pathname.slice(0, -`/${filename}`.length) || "/"; payloadURL.searchParams.delete(PAYLOAD_BUILD_ID_PARAM); return url + payloadURL.search; } const LEADING_SLASHES_RE = /^\/+/; const TRAILING_SLASHES_RE = /\/*$/; /** The same-origin `_payload.json` (or `_payload.js`) URL for a page route, tagged with the build id. */ function routeToPayloadURL(baseURL, path, buildId, filename = "_payload.json") { const request = parseRequestPath(path); const base = new URL(baseURL.replace(TRAILING_SLASHES_RE, "/"), "http://localhost"); const route = request.pathname.replace(LEADING_SLASHES_RE, "").replace(TRAILING_SLASHES_RE, "/"); const url = new URL("./" + (route === "/" ? "" : route) + filename, base); url.search = request.search; url.searchParams.set(PAYLOAD_BUILD_ID_PARAM, buildId); return URL.canParse(baseURL) ? url.href : url.pathname + url.search; } /** `url` with its path and query replaced by those of the request path `path`, keeping its origin. */ function withRequestPath(url, path) { const request = parseRequestPath(path); const target = new URL(url); target.pathname = request.pathname; target.search = request.search; return target; } //#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; } //#region src/runtime/server/renderer/payload.ts function renderPayloadResponse(ssrContext, event) { return { body: encodeForwardSlashes(stringify(splitPayload(ssrContext).payload, ssrContext["~payloadReducers"])) , statusCode: event.res.status, statusMessage: event.res.statusText, headers: { "content-type": "application/json;charset=utf-8" , "x-powered-by": "Nuxt" } }; } 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"); } function splitPayload(ssrContext) { const { data, prerenderedAt, prefetchLinks, ...initial } = ssrContext.payload; const payload = { data, prerenderedAt }; if (prefetchLinks?.length) payload.prefetchLinks = prefetchLinks; return { initial: { ...initial, prerenderedAt }, payload }; } //#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 `