@reckona/mreact-router 0.0.192 → 0.0.194

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/dist/serve.d.ts CHANGED
@@ -5,7 +5,7 @@ import { readBuiltPublicAsset } from "./built-assets.js";
5
5
  import type { AppRouterServerActionOptions } from "./actions.js";
6
6
  import type { AppRouterImportPolicy } from "./import-policy.js";
7
7
  import { type AppRouterRenderPreload, type AppRouterResponseHook } from "./render.js";
8
- import type { RouterInstrumentation } from "./trace.js";
8
+ import { type RouterInstrumentation } from "./trace.js";
9
9
  import { type AppRouterLogger } from "./logger.js";
10
10
  import type { HttpUpgradeHandler } from "./upgrade.js";
11
11
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../src/serve.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAGxC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAKL,oBAAoB,EACrB,MAAM,mBAAmB,CAAC;AAgB3B,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAKL,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAE3B,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAKxD,OAAO,EAIL,KAAK,eAAe,EACrB,MAAM,aAAa,CAAC;AAIrB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAavD;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,oBAAoB,GAAG,QAAQ,GAAG,QAAQ,CAAC;AACvD;;GAEG;AACH,MAAM,MAAM,iBAAiB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EG;AACH,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,4BAA4B,GACpC,OAAO,CAAC,QAAQ,CAAC,CAiBnB;AAyPD;;;;GAIG;AACH,wBAAsB,WAAW,CAC/B,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAAC;IAAE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,CA2BlE;AAED,eAAO,MAAM,6BAA6B,6BAAuB,CAAC;AAElE,wBAAgB,+BAA+B,IAAI,IAAI,CAItD;AAED,wBAAgB,wCAAwC,IAAI,MAAM,CAEjE;AAED,wBAAgB,mCAAmC,IAAI,IAAI,CAE1D;AAED,wBAAgB,qCAAqC,IAAI,MAAM,CAE9D"}
package/dist/serve.js CHANGED
@@ -2,9 +2,10 @@ import { readFile } from "node:fs/promises";
2
2
  import { join } from "node:path";
3
3
  import { builtClientAssetPathname, clearBuiltPublicAssetCacheForTest, getBuiltPublicAssetCacheSizeForTest, readBuiltClientAsset, readBuiltPublicAsset, } from "./built-assets.js";
4
4
  import { materializeBuiltRuntime, mergeBuiltRuntimeImportPolicy, readBuiltImportPolicyText, } from "./built-runtime.js";
5
- import { allBuiltServerModuleFiles, loadBuiltServerModuleArtifacts, loadBuiltServerModuleArtifactsForRequest, } from "./built-server-module-artifacts.js";
5
+ import { allBuiltServerModuleFiles, loadBuiltResponseHookArtifacts, loadBuiltServerModuleArtifacts, loadBuiltServerModuleArtifactsForRequest, } from "./built-server-module-artifacts.js";
6
6
  import {} from "./routes.js";
7
- import { preloadBuiltRequestModules, renderAppRequest, resolveAppRouterMiddleware, } from "./render.js";
7
+ import { preloadBuiltRequestModules, renderAppRequest, resolveAppRouterResponseHook, resolveAppRouterMiddleware, } from "./render.js";
8
+ import { invokeRouterInstrumentation, traceContextFromRequest, } from "./trace.js";
8
9
  import { bytesResponse, htmlResponse, } from "./http.js";
9
10
  import { emitRouterLog, logDurationMs, logNow, } from "./logger.js";
10
11
  import { startNodeRequestServer } from "./node-server.js";
@@ -49,8 +50,10 @@ export async function createBuiltRequestRuntime(options) {
49
50
  });
50
51
  },
51
52
  async render(request, renderOptions = {}) {
53
+ emitBuiltRequestStart(renderOptions.instrumentation, request);
52
54
  const response = await renderBuiltAppRequestWithRuntime({
53
55
  ...renderOptions,
56
+ instrumentation: withoutBuiltRequestInstrumentation(renderOptions.instrumentation),
54
57
  importPolicy: renderOptions.importPolicy === undefined
55
58
  ? defaultImportPolicy
56
59
  : mergeBuiltRuntimeImportPolicy(runtime, renderOptions.importPolicy),
@@ -58,10 +61,12 @@ export async function createBuiltRequestRuntime(options) {
58
61
  request,
59
62
  runtime,
60
63
  });
61
- return applyBuiltAppResponseHook(response, {
64
+ const finalResponse = await applyBuiltAppResponseHook(response, {
62
65
  onResponse: renderOptions.onResponse,
63
66
  request,
64
- });
67
+ }, runtime);
68
+ emitBuiltRequestEnd(renderOptions.instrumentation, request, finalResponse.status);
69
+ return finalResponse;
65
70
  },
66
71
  };
67
72
  }
@@ -129,6 +134,7 @@ function builtRuntimePreloadRoutes(runtime, strategy) {
129
134
  * Renders a request using a built app-router output directory.
130
135
  */
131
136
  export async function renderBuiltAppRequest(options) {
137
+ emitBuiltRequestStart(options.instrumentation, options.request);
132
138
  const runtime = await readBuiltRuntime({
133
139
  outDir: options.outDir,
134
140
  immutable: options.immutableRuntime,
@@ -136,10 +142,39 @@ export async function renderBuiltAppRequest(options) {
136
142
  });
137
143
  const response = await renderBuiltAppRequestWithRuntime({
138
144
  ...options,
145
+ instrumentation: withoutBuiltRequestInstrumentation(options.instrumentation),
139
146
  importPolicy: mergeBuiltRuntimeImportPolicy(runtime, options.importPolicy),
140
147
  runtime,
141
148
  });
142
- return applyBuiltAppResponseHook(response, options);
149
+ const finalResponse = await applyBuiltAppResponseHook(response, options, runtime);
150
+ emitBuiltRequestEnd(options.instrumentation, options.request, finalResponse.status);
151
+ return finalResponse;
152
+ }
153
+ function withoutBuiltRequestInstrumentation(instrumentation) {
154
+ if (instrumentation === undefined) {
155
+ return undefined;
156
+ }
157
+ const { onRequestEnd: _onRequestEnd, onRequestStart: _onRequestStart, ...remaining } = instrumentation;
158
+ return remaining;
159
+ }
160
+ function emitBuiltRequestStart(instrumentation, request) {
161
+ const trace = traceContextFromRequest(request);
162
+ invokeRouterInstrumentation(instrumentation?.onRequestStart, {
163
+ method: request.method,
164
+ path: new URL(request.url).pathname,
165
+ request,
166
+ ...(trace === undefined ? {} : { trace }),
167
+ });
168
+ }
169
+ function emitBuiltRequestEnd(instrumentation, request, status) {
170
+ const trace = traceContextFromRequest(request);
171
+ invokeRouterInstrumentation(instrumentation?.onRequestEnd, {
172
+ method: request.method,
173
+ path: new URL(request.url).pathname,
174
+ request,
175
+ status,
176
+ ...(trace === undefined ? {} : { trace }),
177
+ });
143
178
  }
144
179
  async function renderBuiltAppRequestWithRuntime(options) {
145
180
  const url = new URL(options.request.url);
@@ -253,8 +288,17 @@ function emitBuiltRenderTiming(options, request, timing, status) {
253
288
  type: "router:render:timing",
254
289
  });
255
290
  }
256
- async function applyBuiltAppResponseHook(response, options) {
257
- const hooked = await options.onResponse?.(response, {
291
+ async function applyBuiltAppResponseHook(response, options, runtime) {
292
+ await loadBuiltResponseHookArtifacts(runtime);
293
+ const onResponse = await resolveAppRouterResponseHook({
294
+ appDir: runtime.appDir,
295
+ importPolicy: runtime.generatedImportPolicy,
296
+ onResponse: options.onResponse,
297
+ serverModules: runtime.serverModules,
298
+ serverModuleCacheVersion: runtime.serverModuleCacheVersion,
299
+ serverSourceFiles: runtime.serverSourceFiles,
300
+ });
301
+ const hooked = await onResponse?.(response, {
258
302
  request: options.request,
259
303
  });
260
304
  return hooked instanceof Response ? hooked : response;
@@ -468,6 +512,7 @@ function builtRenderAppRequestOptions(options) {
468
512
  serverActionReferencesByFile: options.runtime.serverActionReferencesByFile,
469
513
  serverActions: mergeBuiltServerActionOptions(options.serverActions, options.runtime.serverActionManifest),
470
514
  skipMiddleware: true,
515
+ onResponse: () => undefined,
471
516
  ...(options.preload === undefined ? {} : { preload: options.preload }),
472
517
  };
473
518
  return renderOptions;
package/dist/serve.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"serve.js","sourceRoot":"","sources":["../src/serve.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,OAAO,EACL,wBAAwB,EACxB,iCAAiC,EACjC,mCAAmC,EACnC,oBAAoB,EACpB,oBAAoB,GACrB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,uBAAuB,EACvB,6BAA6B,EAC7B,yBAAyB,GAE1B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,yBAAyB,EACzB,8BAA8B,EAC9B,wCAAwC,GACzC,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAGN,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,0BAA0B,EAC1B,gBAAgB,EAChB,0BAA0B,GAK3B,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,aAAa,EACb,YAAY,GACb,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,aAAa,EACb,aAAa,EACb,MAAM,GAEP,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,0BAA0B,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAUrD,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAkC,CAAC;AACpE,MAAM,wBAAwB,GAAG,IAAI,GAAG,EAAiC,CAAC;AAC1E,IAAI,mCAAmC,GAAG,CAAC,CAAC;AAqB5C,IAAI,uBAAuB,GAAG,KAAK,CAAC;AA0FpC,MAAM,UAAU,kBAAkB,CAAC,OAKlC;IACC,MAAM,GAAG,GAA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,EAAE,CAAC;IACnC,MAAM,OAAO,GAA2B,EAAE,CAAC;IAE3C,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;QACtC,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IACvB,CAAC,CAAC,CAAC;IACH,MAAM,KAAK,GAAG;QACZ,OAAO;QACP,IAAI,EAAE,IAAI;QACV,MAAM,EAAE,QAAQ,CAAC,MAAM;KACxB,CAAC;IACF,OAAO,CAAC,iBAAiB,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC3C,MAAM,KAAK,EAAE,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAE9B,OAAO,YAAY,CAAC,IAAI,EAAE;QACxB,OAAO,EAAE,QAAQ,CAAC,OAAO;QACzB,MAAM,EAAE,QAAQ,CAAC,MAAM;KACxB,CAAC,CAAC;AACL,CAAC;AAED,KAAK,UAAU,aAAa,CAAC,QAAkB;IAC7C,OAAO,YAAY,CAAC,MAAM,QAAQ,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE;QACjD,OAAO,EAAE,QAAQ,CAAC,OAAO;QACzB,MAAM,EAAE,QAAQ,CAAC,MAAM;KACxB,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { Server } from \"node:http\";\nimport { readFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport type { BuiltPrerenderedRoute } from \"./build.js\";\nimport type { AppRouterCache } from \"./cache.js\";\nimport {\n builtClientAssetPathname,\n clearBuiltPublicAssetCacheForTest,\n getBuiltPublicAssetCacheSizeForTest,\n readBuiltClientAsset,\n readBuiltPublicAsset,\n} from \"./built-assets.js\";\nimport {\n materializeBuiltRuntime,\n mergeBuiltRuntimeImportPolicy,\n readBuiltImportPolicyText,\n type BuiltRuntime,\n} from \"./built-runtime.js\";\nimport {\n allBuiltServerModuleFiles,\n loadBuiltServerModuleArtifacts,\n loadBuiltServerModuleArtifactsForRequest,\n} from \"./built-server-module-artifacts.js\";\nimport {\n type AppRoute,\n type MatchedRoute,\n} from \"./routes.js\";\nimport type { AppRouterServerActionOptions } from \"./actions.js\";\nimport type { AppRouterImportPolicy } from \"./import-policy.js\";\nimport {\n preloadBuiltRequestModules,\n renderAppRequest,\n resolveAppRouterMiddleware,\n type AppRouterServerRenderArtifactLoader,\n type AppRouterRenderPreload,\n type AppRouterResponseHook,\n type RenderAppRequestRuntimeOptions,\n} from \"./render.js\";\nimport type { RouterInstrumentation } from \"./trace.js\";\nimport {\n bytesResponse,\n htmlResponse,\n} from \"./http.js\";\nimport {\n emitRouterLog,\n logDurationMs,\n logNow,\n type AppRouterLogger,\n} from \"./logger.js\";\nimport { startNodeRequestServer } from \"./node-server.js\";\nimport { builtAppRuntimePreloadPlan } from \"./preload-policy.js\";\nimport { normalizeRoutePath } from \"./route-path.js\";\nimport type { HttpUpgradeHandler } from \"./upgrade.js\";\n\ninterface BuiltRuntimeCacheEntry {\n clientManifestText: string;\n importPolicyText: string | undefined;\n runtime: Promise<BuiltRuntime>;\n serverManifestText: string;\n}\n\nconst builtRuntimeCache = new Map<string, BuiltRuntimeCacheEntry>();\nconst builtRuntimeReadInflight = new Map<string, Promise<BuiltRuntime>>();\nlet builtRuntimeMaterializeCountForTest = 0;\n\n/**\n * Strategy for the final response body shape sent to the HTTP layer.\n *\n * - `\"string\"` (default, cross-runtime): body is the raw HTML string. The\n * underlying runtime encodes to UTF-8 bytes when writing to the socket.\n * - `\"buffer\"` (Node only): materialize the response body into a Buffer\n * before returning. Skips the implicit encode at the Response → socket\n * boundary and can let Node's HTTP layer write bytes directly.\n *\n * The buffer path forces full materialization of streaming responses\n * (loses TTFB streaming) — only opt in if the throughput gain outweighs\n * that on your workload.\n */\nexport type ResponseSinkStrategy = \"string\" | \"buffer\";\n/**\n * Controls whether built request handling trusts the incoming Host header.\n */\nexport type RequestHostPolicy = \"strict\" | \"trusted-proxy\";\n\nlet warnedImplicitHostTrust = false;\n\n/**\n * Configures rendering a request against a built app-router output directory.\n */\nexport interface RenderBuiltAppRequestOptions {\n outDir: string;\n importPolicy?: AppRouterImportPolicy | undefined;\n instrumentation?: RouterInstrumentation | undefined;\n logger?: AppRouterLogger | undefined;\n onResponse?: AppRouterResponseHook | undefined;\n prerenderStore?: AppRouterPrerenderStore | undefined;\n request: Request;\n routeCache?: AppRouterCache | undefined;\n runtimeDir?: string | undefined;\n immutableRuntime?: boolean | undefined;\n serverActions?: AppRouterServerActionOptions | undefined;\n sinkStrategy?: ResponseSinkStrategy;\n preload?: AppRouterRenderPreload | undefined;\n}\n\nexport interface BuiltRequestRuntimeOptions {\n immutableRuntime?: boolean | undefined;\n importPolicy?: AppRouterImportPolicy | undefined;\n outDir: string;\n runtimeDir?: string | undefined;\n}\n\nexport type BuiltRequestRuntimeRenderOptions = Omit<\n RenderBuiltAppRequestOptions,\n \"immutableRuntime\" | \"outDir\" | \"request\" | \"runtimeDir\"\n>;\n\nexport interface BuiltRequestRuntime {\n preload(preload?: BuiltAppRuntimePreloadStrategy | undefined): Promise<void>;\n render(\n request: Request,\n options?: BuiltRequestRuntimeRenderOptions | undefined,\n ): Promise<Response>;\n}\n\n/**\n * Selects which built runtime modules should be preloaded.\n */\nexport type BuiltAppRuntimePreloadMode =\n | \"all\"\n | \"hot-route-requests\"\n | \"hot-routes\"\n | \"middleware\"\n | \"none\";\n\n/**\n * Configures built app runtime preload scope and optional hot routes.\n */\nexport interface BuiltAppRuntimePreloadStrategy {\n mode: BuiltAppRuntimePreloadMode;\n routes?: readonly string[] | undefined;\n}\n\n/**\n * Configures the Node HTTP server used to serve a built app-router output.\n */\nexport interface StartServerOptions {\n outDir: string;\n port: number;\n hostname?: string;\n // Optional hook for customizing the 500 response. The default returns\n // a generic \"Internal Server Error\" body and logs the stack to stderr\n // via console.error. Issue 071: stack traces must never end up in\n // production responses.\n errorHandler?: (error: unknown) => { body: string; status: number; headers?: Record<string, string> };\n // When set, an incoming Host header that does not exactly match one of\n // the listed values is replaced with the configured hostname/port for\n // origin reconstruction. Use this in front of public deployments to\n // block Host header injection (Issue 068). Undefined preserves the\n // legacy \"trust Host\" behavior for backward compatibility when\n // hostPolicy is not configured.\n allowedHosts?: readonly string[] | undefined;\n hostPolicy?: RequestHostPolicy | undefined;\n importPolicy?: AppRouterImportPolicy | undefined;\n instrumentation?: RouterInstrumentation | undefined;\n logger?: AppRouterLogger | undefined;\n onResponse?: AppRouterResponseHook | undefined;\n prerenderStore?: AppRouterPrerenderStore | undefined;\n routeCache?: AppRouterCache | undefined;\n serverActions?: AppRouterServerActionOptions | undefined;\n sinkStrategy?: ResponseSinkStrategy;\n onUpgrade?: HttpUpgradeHandler | undefined;\n}\n\nexport function resolveRequestHost(options: {\n allowedHosts?: readonly string[] | undefined;\n fallbackHost: string;\n hostPolicy?: RequestHostPolicy | undefined;\n rawHost: string | undefined;\n}): string {\n const raw = options.rawHost;\n if (raw === undefined || raw === \"\") return options.fallbackHost;\n if (options.allowedHosts === undefined) {\n return options.hostPolicy === \"strict\" ? options.fallbackHost : raw;\n }\n return options.allowedHosts.includes(raw) ? raw : options.fallbackHost;\n}\n\nexport function warnIfImplicitHostTrust(options: {\n allowedHosts?: readonly string[] | undefined;\n hostPolicy?: RequestHostPolicy | undefined;\n}): void {\n if (\n process.env.NODE_ENV !== \"production\" ||\n options.allowedHosts !== undefined ||\n options.hostPolicy !== undefined ||\n warnedImplicitHostTrust\n ) {\n return;\n }\n\n warnedImplicitHostTrust = true;\n console.error(\n \"[mreact] Host header trust is implicit because neither allowedHosts nor hostPolicy is configured. Set allowedHosts for public deployments, hostPolicy: \\\"strict\\\" to reject unlisted Host headers, or hostPolicy: \\\"trusted-proxy\\\" when a trusted reverse proxy normalizes Host.\",\n );\n}\n\n/**\n * Defines storage for prerendered route responses used by built request rendering.\n */\nexport interface AppRouterPrerenderStore {\n delete(path: string): void | Promise<void>;\n get(path: string): BuiltPrerenderedRoute | undefined | Promise<BuiltPrerenderedRoute | undefined>;\n set(path: string, entry: BuiltPrerenderedRoute): void | Promise<void>;\n withLock?<T>(path: string, task: () => Promise<T>): Promise<T>;\n}\n\nexport async function createBuiltRequestRuntime(\n options: BuiltRequestRuntimeOptions,\n): Promise<BuiltRequestRuntime> {\n const runtime = await readBuiltRuntime({\n immutable: options.immutableRuntime,\n outDir: options.outDir,\n runtimeDir: options.runtimeDir,\n });\n const defaultImportPolicy = mergeBuiltRuntimeImportPolicy(runtime, options.importPolicy);\n\n return {\n preload(preload) {\n return preloadBuiltAppRuntimeWithRuntime({\n importPolicy: defaultImportPolicy,\n preload,\n runtime,\n });\n },\n async render(request, renderOptions = {}) {\n const response = await renderBuiltAppRequestWithRuntime({\n ...renderOptions,\n importPolicy:\n renderOptions.importPolicy === undefined\n ? defaultImportPolicy\n : mergeBuiltRuntimeImportPolicy(runtime, renderOptions.importPolicy),\n outDir: options.outDir,\n request,\n runtime,\n });\n\n return applyBuiltAppResponseHook(response, {\n onResponse: renderOptions.onResponse,\n request,\n });\n },\n };\n}\n\n/**\n * Preloads selected modules from a built app-router runtime.\n */\nexport async function preloadBuiltAppRuntime(options: {\n importPolicy?: AppRouterImportPolicy | undefined;\n outDir: string;\n preload?: BuiltAppRuntimePreloadStrategy | undefined;\n runtimeDir?: string | undefined;\n}): Promise<void> {\n const runtime = await readBuiltRuntime({\n outDir: options.outDir,\n runtimeDir: options.runtimeDir,\n });\n await preloadBuiltAppRuntimeWithRuntime({\n importPolicy: mergeBuiltRuntimeImportPolicy(runtime, options.importPolicy),\n preload: options.preload,\n runtime,\n });\n}\n\nasync function preloadBuiltAppRuntimeWithRuntime(options: {\n importPolicy?: AppRouterImportPolicy | undefined;\n preload?: BuiltAppRuntimePreloadStrategy | undefined;\n runtime: BuiltRuntime;\n}): Promise<void> {\n const plan = builtAppRuntimePreloadPlan(options.preload);\n\n if (!plan.shouldPreload) {\n return;\n }\n\n const routes = builtRuntimePreloadRoutes(options.runtime, plan);\n if (plan.loadAllArtifacts) {\n await loadBuiltServerModuleArtifacts(\n options.runtime,\n allBuiltServerModuleFiles(options.runtime),\n \"all\",\n );\n } else {\n await loadBuiltServerModuleArtifactsForRequest(\n options.runtime,\n undefined,\n plan.middlewareArtifacts,\n );\n for (const route of routes) {\n await loadBuiltServerModuleArtifactsForRequest(\n options.runtime,\n route.file,\n plan.routeArtifacts,\n );\n }\n }\n await preloadBuiltRequestModules({\n appDir: options.runtime.appDir,\n importPolicy: {\n ...options.importPolicy,\n allowedSourceDirs: options.runtime.allowedSourceDirs,\n projectRoot: options.runtime.projectRoot,\n },\n routes,\n serverModules: options.runtime.serverModules,\n serverModuleCacheVersion: options.runtime.serverModuleCacheVersion,\n serverSourceFiles: options.runtime.serverSourceFiles,\n serverActionReferencesByFile: options.runtime.serverActionReferencesByFile,\n includeRenderModules: plan.includeRenderModules,\n });\n}\n\nfunction builtRuntimePreloadRoutes(\n runtime: BuiltRuntime,\n strategy: BuiltAppRuntimePreloadStrategy,\n): readonly AppRoute[] {\n if (strategy.mode === \"all\") {\n return runtime.routes;\n }\n\n if (strategy.mode === \"middleware\" || strategy.mode === \"none\") {\n return [];\n }\n\n const routes = strategy.routes ?? [];\n return routes.map((path) => {\n const route = runtime.routeMatcher.match(normalizeRoutePath(path))?.route;\n if (route === undefined) {\n throw new Error(`Unknown hot route preload path: ${path}`);\n }\n return route;\n });\n}\n\n/**\n * Renders a request using a built app-router output directory.\n */\nexport async function renderBuiltAppRequest(\n options: RenderBuiltAppRequestOptions,\n): Promise<Response> {\n const runtime = await readBuiltRuntime({\n outDir: options.outDir,\n immutable: options.immutableRuntime,\n runtimeDir: options.runtimeDir,\n });\n const response = await renderBuiltAppRequestWithRuntime({\n ...options,\n importPolicy: mergeBuiltRuntimeImportPolicy(runtime, options.importPolicy),\n runtime,\n });\n\n return applyBuiltAppResponseHook(response, options);\n}\n\nasync function renderBuiltAppRequestWithRuntime(\n options: RenderBuiltAppRequestOptions & { runtime: BuiltRuntime },\n): Promise<Response> {\n const url = new URL(options.request.url);\n const timing = createBuiltRenderTiming(options.logger);\n\n const clientAssetPathname = builtClientAssetPathname(options.request, url);\n\n if (clientAssetPathname !== undefined) {\n return readBuiltClientAsset(\n options.outDir,\n clientAssetPathname,\n options.runtime.clientAssetPaths,\n );\n }\n\n if (options.request.method === \"GET\" || options.request.method === \"HEAD\") {\n const publicAsset = await readBuiltPublicAsset(options.outDir, url.pathname);\n\n if (publicAsset !== undefined) {\n return publicAsset;\n }\n }\n\n let request = options.request;\n let normalizedPath = normalizeRoutePath(url.pathname);\n let matched = options.runtime.routeMatcher.match(normalizedPath);\n\n if (options.request.method === \"GET\" || options.request.method === \"HEAD\") {\n // Sync fast path when no external prerender store is configured (the\n // common case): skip the Promise wrap that `readPrerenderedRoute`\n // would otherwise introduce just to satisfy the async signature.\n const prerendered =\n options.prerenderStore === undefined\n ? options.runtime.prerenderedRoutes.get(normalizedPath)\n : await readPrerenderedRoute(\n options.runtime,\n normalizedPath,\n options.prerenderStore,\n );\n\n if (prerendered !== undefined) {\n if (options.request.method === \"HEAD\") {\n return new Response(null, {\n headers: prerendered.headers,\n status: prerendered.status,\n });\n }\n return htmlResponse(prerendered.html, {\n headers: prerendered.headers,\n status: prerendered.status,\n });\n }\n }\n\n const middlewareStartedAt = builtRenderTimingPhaseStartedAt(timing);\n const middlewareResult = await resolveBuiltMiddleware({ ...options, timing }, request);\n finishBuiltRenderTimingPhase(timing, middlewareStartedAt, \"middlewareMs\");\n if (middlewareResult.type === \"response\") {\n emitBuiltRenderTiming(options, request, timing, middlewareResult.response.status);\n return middlewareResult.response;\n }\n if (middlewareResult.request !== request) {\n request = middlewareResult.request;\n normalizedPath = normalizeRoutePath(new URL(request.url).pathname);\n matched = options.runtime.routeMatcher.match(normalizedPath);\n }\n\n if (request.method === \"GET\" && options.runtime.prerenderableRoutes.has(normalizedPath)) {\n await loadBuiltServerModuleArtifactsForRequest(options.runtime, matched?.route.file, {\n includeRender: false,\n });\n return renderAndCachePrerenderWithLock({ ...options, request }, normalizedPath);\n }\n\n await loadBuiltServerModuleArtifactsForRequest(options.runtime, matched?.route.file, {\n includeRender: false,\n });\n const response = await renderBuiltDynamicResponse({\n ...options,\n matchedRoute: matched,\n request,\n requestUrl: new URL(request.url),\n });\n\n await applyBuiltPrerenderInvalidations(\n options.runtime,\n response,\n options.prerenderStore,\n );\n\n return options.sinkStrategy === \"buffer\"\n ? await materializeResponseAsBuffer(response)\n : response;\n}\n\nasync function resolveBuiltMiddleware(\n options: RenderBuiltAppRequestOptions & {\n runtime: BuiltRuntime;\n timing?: { phases: Record<string, number> } | undefined;\n },\n request: Request,\n): Promise<{ request: Request; type: \"continue\" } | { response: Response; type: \"response\" }> {\n if (!options.runtime.hasMiddleware) {\n return { request, type: \"continue\" };\n }\n\n await loadBuiltServerModuleArtifactsForRequest(options.runtime, undefined);\n\n return resolveAppRouterMiddleware({\n appDir: options.runtime.appDir,\n importPolicy: {\n ...options.importPolicy,\n allowedSourceDirs: options.runtime.allowedSourceDirs,\n projectRoot: options.runtime.projectRoot,\n },\n instrumentation: options.instrumentation,\n request,\n serverModules: options.runtime.serverModules,\n serverModuleCacheVersion: options.runtime.serverModuleCacheVersion,\n serverSourceFiles: options.runtime.serverSourceFiles,\n timing: options.timing,\n });\n}\n\nfunction createBuiltRenderTiming(\n logger: AppRouterLogger | undefined,\n): { phases: Record<string, number> } | undefined {\n return logger?.debug === undefined ? undefined : { phases: {} };\n}\n\nfunction builtRenderTimingPhaseStartedAt(\n timing: { phases: Record<string, number> } | undefined,\n): number | undefined {\n return timing === undefined ? undefined : logNow();\n}\n\nfunction finishBuiltRenderTimingPhase(\n timing: { phases: Record<string, number> } | undefined,\n startedAt: number | undefined,\n phaseName: string,\n): void {\n if (timing === undefined || startedAt === undefined) {\n return;\n }\n\n timing.phases[phaseName] = logDurationMs(startedAt);\n}\n\nfunction emitBuiltRenderTiming(\n options: RenderBuiltAppRequestOptions,\n request: Request,\n timing: { phases: Record<string, number> } | undefined,\n status: number,\n): void {\n if (timing === undefined) {\n return;\n }\n\n emitRouterLog(options.logger, \"debug\", {\n method: request.method,\n path: new URL(request.url).pathname,\n phases: timing.phases,\n status,\n type: \"router:render:timing\",\n });\n}\n\nasync function applyBuiltAppResponseHook(\n response: Response,\n options: Pick<RenderBuiltAppRequestOptions, \"onResponse\" | \"request\">,\n): Promise<Response> {\n const hooked = await options.onResponse?.(response, {\n request: options.request,\n });\n\n return hooked instanceof Response ? hooked : response;\n}\n\nasync function materializeResponseAsBuffer(response: Response): Promise<Response> {\n if (response.body === null) {\n return response;\n }\n\n // Drains streaming responses into a single Buffer (loses TTFB streaming\n // by design — opt-in via sinkStrategy === \"buffer\"). Avoids the\n // string → UTF-8 encode the Response stream would otherwise do lazily\n // during the socket write. Tagged via `bytesResponse` so `sendResponse`\n // can take the raw-bytes fast path.\n const bytes = new Uint8Array(await response.arrayBuffer());\n return bytesResponse(bytes, {\n headers: response.headers,\n status: response.status,\n statusText: response.statusText,\n });\n}\n\n/**\n * Starts a Node HTTP server for an already built app-router output directory.\n *\n * Use this for production-like local serving or custom Node deployments. It loads `.mreact/server` artifacts, applies the generated import policy when configured, enforces host trust options, and returns a `close()` method for orderly shutdown.\n */\nexport async function startServer(\n options: StartServerOptions,\n): Promise<{ close(): Promise<void>; server: Server; url: string }> {\n warnIfImplicitHostTrust(options);\n const runtime = await createBuiltRequestRuntime({\n importPolicy: options.importPolicy,\n outDir: options.outDir,\n });\n\n return await startNodeRequestServer({\n allowedHosts: options.allowedHosts,\n errorHandler: options.errorHandler,\n hostname: options.hostname,\n hostPolicy: options.hostPolicy,\n logger: options.logger,\n onUpgrade: options.onUpgrade,\n port: options.port,\n resolveHost: resolveRequestHost,\n render: (request) =>\n runtime.render(request, {\n instrumentation: options.instrumentation,\n logger: options.logger,\n onResponse: options.onResponse,\n prerenderStore: options.prerenderStore,\n routeCache: options.routeCache,\n serverActions: options.serverActions,\n ...(options.sinkStrategy === undefined ? {} : { sinkStrategy: options.sinkStrategy }),\n }),\n });\n}\n\nexport const __readBuiltPublicAssetForTest = readBuiltPublicAsset;\n\nexport function __clearBuiltRuntimeCacheForTest(): void {\n builtRuntimeCache.clear();\n builtRuntimeReadInflight.clear();\n builtRuntimeMaterializeCountForTest = 0;\n}\n\nexport function __getBuiltRuntimeMaterializeCountForTest(): number {\n return builtRuntimeMaterializeCountForTest;\n}\n\nexport function __clearBuiltPublicAssetCacheForTest(): void {\n clearBuiltPublicAssetCacheForTest();\n}\n\nexport function __getBuiltPublicAssetCacheSizeForTest(): number {\n return getBuiltPublicAssetCacheSizeForTest();\n}\n\nasync function readBuiltRuntime(options: {\n immutable?: boolean | undefined;\n outDir: string;\n runtimeDir?: string | undefined;\n}): Promise<BuiltRuntime> {\n const outDir = options.outDir;\n const runtimeDir = options.runtimeDir ?? join(outDir, \"server\", \"runtime\");\n const cacheKey = `${outDir}\\0${runtimeDir}`;\n const cached = builtRuntimeCache.get(cacheKey);\n\n if (options.immutable === true && cached !== undefined) {\n return cached.runtime;\n }\n\n if (cached === undefined) {\n const inflight = builtRuntimeReadInflight.get(cacheKey);\n if (inflight !== undefined) {\n return inflight;\n }\n\n const runtime = readBuiltRuntimeUncached({\n cacheKey,\n cached,\n outDir,\n runtimeDir,\n });\n builtRuntimeReadInflight.set(cacheKey, runtime);\n void runtime\n .finally(() => {\n if (builtRuntimeReadInflight.get(cacheKey) === runtime) {\n builtRuntimeReadInflight.delete(cacheKey);\n }\n })\n .catch(() => {});\n return runtime;\n }\n\n return readBuiltRuntimeUncached({\n cacheKey,\n cached,\n outDir,\n runtimeDir,\n });\n}\n\nasync function readBuiltRuntimeUncached(options: {\n cached: BuiltRuntimeCacheEntry | undefined;\n cacheKey: string;\n outDir: string;\n runtimeDir: string;\n}): Promise<BuiltRuntime> {\n const { cacheKey, cached, outDir, runtimeDir } = options;\n const serverManifestPath = join(outDir, \"server\", \"manifest.json\");\n const clientManifestPath = join(outDir, \"client\", \"manifest.json\");\n const importPolicyPath = join(outDir, \"server\", \"import-policy.json\");\n const [serverManifestText, clientManifestText, importPolicyText] = await Promise.all([\n readRequiredBuiltArtifactText(serverManifestPath, \"built app server manifest\"),\n readRequiredBuiltArtifactText(clientManifestPath, \"built app client manifest\"),\n readBuiltImportPolicyText(outDir),\n ]);\n\n if (\n cached !== undefined &&\n cached.serverManifestText === serverManifestText &&\n cached.clientManifestText === clientManifestText &&\n cached.importPolicyText === importPolicyText\n ) {\n return cached.runtime;\n }\n\n const runtime = materializeBuiltRuntime({\n clientManifestText,\n clientManifestPath,\n importPolicyText,\n importPolicyPath,\n onMaterialize() {\n builtRuntimeMaterializeCountForTest += 1;\n },\n outDir,\n runtimeDir,\n serverManifestText,\n serverManifestPath,\n });\n\n builtRuntimeCache.set(cacheKey, {\n clientManifestText,\n importPolicyText,\n runtime,\n serverManifestText,\n });\n runtime.catch(() => {\n if (builtRuntimeCache.get(cacheKey)?.runtime === runtime) {\n builtRuntimeCache.delete(cacheKey);\n }\n });\n\n return runtime;\n}\n\nfunction isMissingFileError(error: unknown): boolean {\n return (\n typeof error === \"object\" &&\n error !== null &&\n \"code\" in error &&\n (error as { code?: unknown }).code === \"ENOENT\"\n );\n}\n\nasync function readRequiredBuiltArtifactText(labelPath: string, label: string): Promise<string> {\n try {\n return await readFile(labelPath, \"utf8\");\n } catch (error) {\n throw builtArtifactReadError(label, labelPath, error);\n }\n}\n\nfunction builtArtifactReadError(label: string, artifactPath: string, error: unknown): Error {\n const prefix = isMissingFileError(error) ? \"Missing\" : \"Unable to read\";\n const detail = error instanceof Error && error.message !== \"\" ? `: ${error.message}` : \"\";\n\n return new Error(`${prefix} ${label}: ${artifactPath}${detail}`, { cause: error });\n}\n\nasync function readPrerenderedRoute(\n runtime: BuiltRuntime,\n path: string,\n store: AppRouterPrerenderStore | undefined,\n): Promise<BuiltPrerenderedRoute | undefined> {\n const stored = await store?.get(path);\n\n if (stored !== undefined) {\n runtime.prerenderedRoutes.set(path, stored);\n return stored;\n }\n\n const manifestEntry = runtime.prerenderedRoutes.get(path);\n\n if (manifestEntry !== undefined && store !== undefined) {\n await store.set(path, manifestEntry);\n }\n\n return manifestEntry;\n}\n\nfunction renderBuiltDynamicResponse(\n options: RenderBuiltAppRequestOptions & {\n matchedRoute?: MatchedRoute | undefined;\n requestUrl?: URL | undefined;\n runtime: BuiltRuntime;\n },\n): Promise<Response> {\n return renderAppRequest(builtRenderAppRequestOptions(options));\n}\n\nfunction builtRenderAppRequestOptions(\n options: RenderBuiltAppRequestOptions & {\n matchedRoute?: MatchedRoute | undefined;\n requestUrl?: URL | undefined;\n runtime: BuiltRuntime;\n },\n): RenderAppRequestRuntimeOptions {\n const serverRenderArtifactLoader: AppRouterServerRenderArtifactLoader = {\n async load(routeFile: string) {\n await loadBuiltServerModuleArtifactsForRequest(options.runtime, routeFile, {\n includeRender: true,\n });\n },\n };\n const renderOptions: RenderAppRequestRuntimeOptions = {\n appDir: options.runtime.appDir,\n assetBaseUrl: options.runtime.assetBaseUrl,\n clientScripts: options.runtime.clientScripts,\n clientStylesByFile: options.runtime.clientStylesByFile,\n clientStyles: options.runtime.clientStyles,\n importPolicy: {\n ...options.importPolicy,\n allowedSourceDirs: options.runtime.allowedSourceDirs,\n projectRoot: options.runtime.projectRoot,\n },\n request: options.request,\n instrumentation: options.instrumentation,\n logger: options.logger,\n matchedRoute: options.matchedRoute,\n navigationScripts: options.runtime.navigationScripts,\n routeCache: options.routeCache,\n routeMatcher: options.runtime.routeMatcher,\n requestUrl: options.requestUrl,\n routes: options.runtime.routes,\n serverRenderArtifactLoader,\n serverModules: options.runtime.serverModules,\n serverModuleCacheVersion: options.runtime.serverModuleCacheVersion,\n serverSourceFiles: options.runtime.serverSourceFiles,\n serverActionReferencesByFile: options.runtime.serverActionReferencesByFile,\n serverActions: mergeBuiltServerActionOptions(\n options.serverActions,\n options.runtime.serverActionManifest,\n ),\n skipMiddleware: true,\n ...(options.preload === undefined ? {} : { preload: options.preload }),\n };\n\n return renderOptions;\n}\n\nfunction mergeBuiltServerActionOptions(\n options: AppRouterServerActionOptions | undefined,\n allowedActions: readonly { moduleId: string; exportName: string; inferred?: boolean }[] | undefined,\n): AppRouterServerActionOptions | undefined {\n if (allowedActions === undefined) {\n return options;\n }\n\n return {\n ...options,\n allowedActions,\n };\n}\n\nasync function renderAndCachePrerenderWithLock(\n options: RenderBuiltAppRequestOptions & { runtime: BuiltRuntime },\n path: string,\n): Promise<Response> {\n const existing = options.runtime.prerenderLocks.get(path);\n\n if (existing !== undefined) {\n return cloneResponse(await existing);\n }\n\n const task = runPrerenderRegeneration(options, path);\n options.runtime.prerenderLocks.set(path, task);\n\n try {\n return cloneResponse(await task);\n } finally {\n options.runtime.prerenderLocks.delete(path);\n }\n}\n\nasync function runPrerenderRegeneration(\n options: RenderBuiltAppRequestOptions & { runtime: BuiltRuntime },\n path: string,\n): Promise<Response> {\n const regenerate = async () => {\n const stored = await readPrerenderedRoute(options.runtime, path, options.prerenderStore);\n\n if (stored !== undefined) {\n return htmlResponse(stored.html, {\n headers: stored.headers,\n status: stored.status,\n });\n }\n\n const response = await renderBuiltDynamicResponse(options);\n\n return response.ok\n ? await cacheRegeneratedPrerenderedRoute(\n options.runtime,\n path,\n response,\n options.prerenderStore,\n )\n : response;\n };\n\n return options.prerenderStore?.withLock === undefined\n ? await regenerate()\n : await options.prerenderStore.withLock(path, regenerate);\n}\n\nasync function applyBuiltPrerenderInvalidations(\n runtime: BuiltRuntime,\n response: Response,\n store: AppRouterPrerenderStore | undefined,\n): Promise<void> {\n const revalidated = response.headers.get(\"x-mreact-revalidate\");\n\n if (revalidated === null) {\n return;\n }\n\n for (const path of revalidated.split(\",\")) {\n const normalized = normalizeRoutePath(path.trim());\n runtime.prerenderedRoutes.delete(normalized);\n await store?.delete(normalized);\n }\n}\n\nasync function cacheRegeneratedPrerenderedRoute(\n runtime: BuiltRuntime,\n path: string,\n response: Response,\n store: AppRouterPrerenderStore | undefined,\n): Promise<Response> {\n const body = await response.text();\n const headers: Record<string, string> = {};\n\n response.headers.forEach((value, key) => {\n headers[key] = value;\n });\n const entry = {\n headers,\n html: body,\n status: response.status,\n };\n runtime.prerenderedRoutes.set(path, entry);\n await store?.set(path, entry);\n\n return htmlResponse(body, {\n headers: response.headers,\n status: response.status,\n });\n}\n\nasync function cloneResponse(response: Response): Promise<Response> {\n return htmlResponse(await response.clone().text(), {\n headers: response.headers,\n status: response.status,\n });\n}\n"]}
1
+ {"version":3,"file":"serve.js","sourceRoot":"","sources":["../src/serve.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,OAAO,EACL,wBAAwB,EACxB,iCAAiC,EACjC,mCAAmC,EACnC,oBAAoB,EACpB,oBAAoB,GACrB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,uBAAuB,EACvB,6BAA6B,EAC7B,yBAAyB,GAE1B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,yBAAyB,EACzB,8BAA8B,EAC9B,8BAA8B,EAC9B,wCAAwC,GACzC,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAGN,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,0BAA0B,EAC1B,gBAAgB,EAChB,4BAA4B,EAC5B,0BAA0B,GAK3B,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,2BAA2B,EAC3B,uBAAuB,GAExB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,aAAa,EACb,YAAY,GACb,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,aAAa,EACb,aAAa,EACb,MAAM,GAEP,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,0BAA0B,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAUrD,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAkC,CAAC;AACpE,MAAM,w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,QAAQ,CAAC,MAAM;KACxB,CAAC;IACF,OAAO,CAAC,iBAAiB,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC3C,MAAM,KAAK,EAAE,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAE9B,OAAO,YAAY,CAAC,IAAI,EAAE;QACxB,OAAO,EAAE,QAAQ,CAAC,OAAO;QACzB,MAAM,EAAE,QAAQ,CAAC,MAAM;KACxB,CAAC,CAAC;AACL,CAAC;AAED,KAAK,UAAU,aAAa,CAAC,QAAkB;IAC7C,OAAO,YAAY,CAAC,MAAM,QAAQ,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE;QACjD,OAAO,EAAE,QAAQ,CAAC,OAAO;QACzB,MAAM,EAAE,QAAQ,CAAC,MAAM;KACxB,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { Server } from \"node:http\";\nimport { readFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport type { BuiltPrerenderedRoute } from \"./build.js\";\nimport type { AppRouterCache } from \"./cache.js\";\nimport {\n builtClientAssetPathname,\n clearBuiltPublicAssetCacheForTest,\n getBuiltPublicAssetCacheSizeForTest,\n readBuiltClientAsset,\n readBuiltPublicAsset,\n} from \"./built-assets.js\";\nimport {\n materializeBuiltRuntime,\n mergeBuiltRuntimeImportPolicy,\n readBuiltImportPolicyText,\n type BuiltRuntime,\n} from \"./built-runtime.js\";\nimport {\n allBuiltServerModuleFiles,\n loadBuiltResponseHookArtifacts,\n loadBuiltServerModuleArtifacts,\n loadBuiltServerModuleArtifactsForRequest,\n} from \"./built-server-module-artifacts.js\";\nimport {\n type AppRoute,\n type MatchedRoute,\n} from \"./routes.js\";\nimport type { AppRouterServerActionOptions } from \"./actions.js\";\nimport type { AppRouterImportPolicy } from \"./import-policy.js\";\nimport {\n preloadBuiltRequestModules,\n renderAppRequest,\n resolveAppRouterResponseHook,\n resolveAppRouterMiddleware,\n type AppRouterServerRenderArtifactLoader,\n type AppRouterRenderPreload,\n type AppRouterResponseHook,\n type RenderAppRequestRuntimeOptions,\n} from \"./render.js\";\nimport {\n invokeRouterInstrumentation,\n traceContextFromRequest,\n type RouterInstrumentation,\n} from \"./trace.js\";\nimport {\n bytesResponse,\n htmlResponse,\n} from \"./http.js\";\nimport {\n emitRouterLog,\n logDurationMs,\n logNow,\n type AppRouterLogger,\n} from \"./logger.js\";\nimport { startNodeRequestServer } from \"./node-server.js\";\nimport { builtAppRuntimePreloadPlan } from \"./preload-policy.js\";\nimport { normalizeRoutePath } from \"./route-path.js\";\nimport type { HttpUpgradeHandler } from \"./upgrade.js\";\n\ninterface BuiltRuntimeCacheEntry {\n clientManifestText: string;\n importPolicyText: string | undefined;\n runtime: Promise<BuiltRuntime>;\n serverManifestText: string;\n}\n\nconst builtRuntimeCache = new Map<string, BuiltRuntimeCacheEntry>();\nconst builtRuntimeReadInflight = new Map<string, Promise<BuiltRuntime>>();\nlet builtRuntimeMaterializeCountForTest = 0;\n\n/**\n * Strategy for the final response body shape sent to the HTTP layer.\n *\n * - `\"string\"` (default, cross-runtime): body is the raw HTML string. The\n * underlying runtime encodes to UTF-8 bytes when writing to the socket.\n * - `\"buffer\"` (Node only): materialize the response body into a Buffer\n * before returning. Skips the implicit encode at the Response → socket\n * boundary and can let Node's HTTP layer write bytes directly.\n *\n * The buffer path forces full materialization of streaming responses\n * (loses TTFB streaming) — only opt in if the throughput gain outweighs\n * that on your workload.\n */\nexport type ResponseSinkStrategy = \"string\" | \"buffer\";\n/**\n * Controls whether built request handling trusts the incoming Host header.\n */\nexport type RequestHostPolicy = \"strict\" | \"trusted-proxy\";\n\nlet warnedImplicitHostTrust = false;\n\n/**\n * Configures rendering a request against a built app-router output directory.\n */\nexport interface RenderBuiltAppRequestOptions {\n outDir: string;\n importPolicy?: AppRouterImportPolicy | undefined;\n instrumentation?: RouterInstrumentation | undefined;\n logger?: AppRouterLogger | undefined;\n onResponse?: AppRouterResponseHook | undefined;\n prerenderStore?: AppRouterPrerenderStore | undefined;\n request: Request;\n routeCache?: AppRouterCache | undefined;\n runtimeDir?: string | undefined;\n immutableRuntime?: boolean | undefined;\n serverActions?: AppRouterServerActionOptions | undefined;\n sinkStrategy?: ResponseSinkStrategy;\n preload?: AppRouterRenderPreload | undefined;\n}\n\nexport interface BuiltRequestRuntimeOptions {\n immutableRuntime?: boolean | undefined;\n importPolicy?: AppRouterImportPolicy | undefined;\n outDir: string;\n runtimeDir?: string | undefined;\n}\n\nexport type BuiltRequestRuntimeRenderOptions = Omit<\n RenderBuiltAppRequestOptions,\n \"immutableRuntime\" | \"outDir\" | \"request\" | \"runtimeDir\"\n>;\n\nexport interface BuiltRequestRuntime {\n preload(preload?: BuiltAppRuntimePreloadStrategy | undefined): Promise<void>;\n render(\n request: Request,\n options?: BuiltRequestRuntimeRenderOptions | undefined,\n ): Promise<Response>;\n}\n\n/**\n * Selects which built runtime modules should be preloaded.\n */\nexport type BuiltAppRuntimePreloadMode =\n | \"all\"\n | \"hot-route-requests\"\n | \"hot-routes\"\n | \"middleware\"\n | \"none\";\n\n/**\n * Configures built app runtime preload scope and optional hot routes.\n */\nexport interface BuiltAppRuntimePreloadStrategy {\n mode: BuiltAppRuntimePreloadMode;\n routes?: readonly string[] | undefined;\n}\n\n/**\n * Configures the Node HTTP server used to serve a built app-router output.\n */\nexport interface StartServerOptions {\n outDir: string;\n port: number;\n hostname?: string;\n // Optional hook for customizing the 500 response. The default returns\n // a generic \"Internal Server Error\" body and logs the stack to stderr\n // via console.error. Issue 071: stack traces must never end up in\n // production responses.\n errorHandler?: (error: unknown) => { body: string; status: number; headers?: Record<string, string> };\n // When set, an incoming Host header that does not exactly match one of\n // the listed values is replaced with the configured hostname/port for\n // origin reconstruction. Use this in front of public deployments to\n // block Host header injection (Issue 068). Undefined preserves the\n // legacy \"trust Host\" behavior for backward compatibility when\n // hostPolicy is not configured.\n allowedHosts?: readonly string[] | undefined;\n hostPolicy?: RequestHostPolicy | undefined;\n importPolicy?: AppRouterImportPolicy | undefined;\n instrumentation?: RouterInstrumentation | undefined;\n logger?: AppRouterLogger | undefined;\n onResponse?: AppRouterResponseHook | undefined;\n prerenderStore?: AppRouterPrerenderStore | undefined;\n routeCache?: AppRouterCache | undefined;\n serverActions?: AppRouterServerActionOptions | undefined;\n sinkStrategy?: ResponseSinkStrategy;\n onUpgrade?: HttpUpgradeHandler | undefined;\n}\n\nexport function resolveRequestHost(options: {\n allowedHosts?: readonly string[] | undefined;\n fallbackHost: string;\n hostPolicy?: RequestHostPolicy | undefined;\n rawHost: string | undefined;\n}): string {\n const raw = options.rawHost;\n if (raw === undefined || raw === \"\") return options.fallbackHost;\n if (options.allowedHosts === undefined) {\n return options.hostPolicy === \"strict\" ? options.fallbackHost : raw;\n }\n return options.allowedHosts.includes(raw) ? raw : options.fallbackHost;\n}\n\nexport function warnIfImplicitHostTrust(options: {\n allowedHosts?: readonly string[] | undefined;\n hostPolicy?: RequestHostPolicy | undefined;\n}): void {\n if (\n process.env.NODE_ENV !== \"production\" ||\n options.allowedHosts !== undefined ||\n options.hostPolicy !== undefined ||\n warnedImplicitHostTrust\n ) {\n return;\n }\n\n warnedImplicitHostTrust = true;\n console.error(\n \"[mreact] Host header trust is implicit because neither allowedHosts nor hostPolicy is configured. Set allowedHosts for public deployments, hostPolicy: \\\"strict\\\" to reject unlisted Host headers, or hostPolicy: \\\"trusted-proxy\\\" when a trusted reverse proxy normalizes Host.\",\n );\n}\n\n/**\n * Defines storage for prerendered route responses used by built request rendering.\n */\nexport interface AppRouterPrerenderStore {\n delete(path: string): void | Promise<void>;\n get(path: string): BuiltPrerenderedRoute | undefined | Promise<BuiltPrerenderedRoute | undefined>;\n set(path: string, entry: BuiltPrerenderedRoute): void | Promise<void>;\n withLock?<T>(path: string, task: () => Promise<T>): Promise<T>;\n}\n\nexport async function createBuiltRequestRuntime(\n options: BuiltRequestRuntimeOptions,\n): Promise<BuiltRequestRuntime> {\n const runtime = await readBuiltRuntime({\n immutable: options.immutableRuntime,\n outDir: options.outDir,\n runtimeDir: options.runtimeDir,\n });\n const defaultImportPolicy = mergeBuiltRuntimeImportPolicy(runtime, options.importPolicy);\n\n return {\n preload(preload) {\n return preloadBuiltAppRuntimeWithRuntime({\n importPolicy: defaultImportPolicy,\n preload,\n runtime,\n });\n },\n async render(request, renderOptions = {}) {\n emitBuiltRequestStart(renderOptions.instrumentation, request);\n const response = await renderBuiltAppRequestWithRuntime({\n ...renderOptions,\n instrumentation: withoutBuiltRequestInstrumentation(renderOptions.instrumentation),\n importPolicy:\n renderOptions.importPolicy === undefined\n ? defaultImportPolicy\n : mergeBuiltRuntimeImportPolicy(runtime, renderOptions.importPolicy),\n outDir: options.outDir,\n request,\n runtime,\n });\n\n const finalResponse = await applyBuiltAppResponseHook(\n response,\n {\n onResponse: renderOptions.onResponse,\n request,\n },\n runtime,\n );\n emitBuiltRequestEnd(renderOptions.instrumentation, request, finalResponse.status);\n return finalResponse;\n },\n };\n}\n\n/**\n * Preloads selected modules from a built app-router runtime.\n */\nexport async function preloadBuiltAppRuntime(options: {\n importPolicy?: AppRouterImportPolicy | undefined;\n outDir: string;\n preload?: BuiltAppRuntimePreloadStrategy | undefined;\n runtimeDir?: string | undefined;\n}): Promise<void> {\n const runtime = await readBuiltRuntime({\n outDir: options.outDir,\n runtimeDir: options.runtimeDir,\n });\n await preloadBuiltAppRuntimeWithRuntime({\n importPolicy: mergeBuiltRuntimeImportPolicy(runtime, options.importPolicy),\n preload: options.preload,\n runtime,\n });\n}\n\nasync function preloadBuiltAppRuntimeWithRuntime(options: {\n importPolicy?: AppRouterImportPolicy | undefined;\n preload?: BuiltAppRuntimePreloadStrategy | undefined;\n runtime: BuiltRuntime;\n}): Promise<void> {\n const plan = builtAppRuntimePreloadPlan(options.preload);\n\n if (!plan.shouldPreload) {\n return;\n }\n\n const routes = builtRuntimePreloadRoutes(options.runtime, plan);\n if (plan.loadAllArtifacts) {\n await loadBuiltServerModuleArtifacts(\n options.runtime,\n allBuiltServerModuleFiles(options.runtime),\n \"all\",\n );\n } else {\n await loadBuiltServerModuleArtifactsForRequest(\n options.runtime,\n undefined,\n plan.middlewareArtifacts,\n );\n for (const route of routes) {\n await loadBuiltServerModuleArtifactsForRequest(\n options.runtime,\n route.file,\n plan.routeArtifacts,\n );\n }\n }\n await preloadBuiltRequestModules({\n appDir: options.runtime.appDir,\n importPolicy: {\n ...options.importPolicy,\n allowedSourceDirs: options.runtime.allowedSourceDirs,\n projectRoot: options.runtime.projectRoot,\n },\n routes,\n serverModules: options.runtime.serverModules,\n serverModuleCacheVersion: options.runtime.serverModuleCacheVersion,\n serverSourceFiles: options.runtime.serverSourceFiles,\n serverActionReferencesByFile: options.runtime.serverActionReferencesByFile,\n includeRenderModules: plan.includeRenderModules,\n });\n}\n\nfunction builtRuntimePreloadRoutes(\n runtime: BuiltRuntime,\n strategy: BuiltAppRuntimePreloadStrategy,\n): readonly AppRoute[] {\n if (strategy.mode === \"all\") {\n return runtime.routes;\n }\n\n if (strategy.mode === \"middleware\" || strategy.mode === \"none\") {\n return [];\n }\n\n const routes = strategy.routes ?? [];\n return routes.map((path) => {\n const route = runtime.routeMatcher.match(normalizeRoutePath(path))?.route;\n if (route === undefined) {\n throw new Error(`Unknown hot route preload path: ${path}`);\n }\n return route;\n });\n}\n\n/**\n * Renders a request using a built app-router output directory.\n */\nexport async function renderBuiltAppRequest(\n options: RenderBuiltAppRequestOptions,\n): Promise<Response> {\n emitBuiltRequestStart(options.instrumentation, options.request);\n const runtime = await readBuiltRuntime({\n outDir: options.outDir,\n immutable: options.immutableRuntime,\n runtimeDir: options.runtimeDir,\n });\n const response = await renderBuiltAppRequestWithRuntime({\n ...options,\n instrumentation: withoutBuiltRequestInstrumentation(options.instrumentation),\n importPolicy: mergeBuiltRuntimeImportPolicy(runtime, options.importPolicy),\n runtime,\n });\n\n const finalResponse = await applyBuiltAppResponseHook(response, options, runtime);\n emitBuiltRequestEnd(options.instrumentation, options.request, finalResponse.status);\n return finalResponse;\n}\n\nfunction withoutBuiltRequestInstrumentation(\n instrumentation: RouterInstrumentation | undefined,\n): RouterInstrumentation | undefined {\n if (instrumentation === undefined) {\n return undefined;\n }\n\n const { onRequestEnd: _onRequestEnd, onRequestStart: _onRequestStart, ...remaining } =\n instrumentation;\n return remaining;\n}\n\nfunction emitBuiltRequestStart(\n instrumentation: RouterInstrumentation | undefined,\n request: Request,\n): void {\n const trace = traceContextFromRequest(request);\n invokeRouterInstrumentation(instrumentation?.onRequestStart, {\n method: request.method,\n path: new URL(request.url).pathname,\n request,\n ...(trace === undefined ? {} : { trace }),\n });\n}\n\nfunction emitBuiltRequestEnd(\n instrumentation: RouterInstrumentation | undefined,\n request: Request,\n status: number,\n): void {\n const trace = traceContextFromRequest(request);\n invokeRouterInstrumentation(instrumentation?.onRequestEnd, {\n method: request.method,\n path: new URL(request.url).pathname,\n request,\n status,\n ...(trace === undefined ? {} : { trace }),\n });\n}\n\nasync function renderBuiltAppRequestWithRuntime(\n options: RenderBuiltAppRequestOptions & { runtime: BuiltRuntime },\n): Promise<Response> {\n const url = new URL(options.request.url);\n const timing = createBuiltRenderTiming(options.logger);\n\n const clientAssetPathname = builtClientAssetPathname(options.request, url);\n\n if (clientAssetPathname !== undefined) {\n return readBuiltClientAsset(\n options.outDir,\n clientAssetPathname,\n options.runtime.clientAssetPaths,\n );\n }\n\n if (options.request.method === \"GET\" || options.request.method === \"HEAD\") {\n const publicAsset = await readBuiltPublicAsset(options.outDir, url.pathname);\n\n if (publicAsset !== undefined) {\n return publicAsset;\n }\n }\n\n let request = options.request;\n let normalizedPath = normalizeRoutePath(url.pathname);\n let matched = options.runtime.routeMatcher.match(normalizedPath);\n\n if (options.request.method === \"GET\" || options.request.method === \"HEAD\") {\n // Sync fast path when no external prerender store is configured (the\n // common case): skip the Promise wrap that `readPrerenderedRoute`\n // would otherwise introduce just to satisfy the async signature.\n const prerendered =\n options.prerenderStore === undefined\n ? options.runtime.prerenderedRoutes.get(normalizedPath)\n : await readPrerenderedRoute(\n options.runtime,\n normalizedPath,\n options.prerenderStore,\n );\n\n if (prerendered !== undefined) {\n if (options.request.method === \"HEAD\") {\n return new Response(null, {\n headers: prerendered.headers,\n status: prerendered.status,\n });\n }\n return htmlResponse(prerendered.html, {\n headers: prerendered.headers,\n status: prerendered.status,\n });\n }\n }\n\n const middlewareStartedAt = builtRenderTimingPhaseStartedAt(timing);\n const middlewareResult = await resolveBuiltMiddleware({ ...options, timing }, request);\n finishBuiltRenderTimingPhase(timing, middlewareStartedAt, \"middlewareMs\");\n if (middlewareResult.type === \"response\") {\n emitBuiltRenderTiming(options, request, timing, middlewareResult.response.status);\n return middlewareResult.response;\n }\n if (middlewareResult.request !== request) {\n request = middlewareResult.request;\n normalizedPath = normalizeRoutePath(new URL(request.url).pathname);\n matched = options.runtime.routeMatcher.match(normalizedPath);\n }\n\n if (request.method === \"GET\" && options.runtime.prerenderableRoutes.has(normalizedPath)) {\n await loadBuiltServerModuleArtifactsForRequest(options.runtime, matched?.route.file, {\n includeRender: false,\n });\n return renderAndCachePrerenderWithLock({ ...options, request }, normalizedPath);\n }\n\n await loadBuiltServerModuleArtifactsForRequest(options.runtime, matched?.route.file, {\n includeRender: false,\n });\n const response = await renderBuiltDynamicResponse({\n ...options,\n matchedRoute: matched,\n request,\n requestUrl: new URL(request.url),\n });\n\n await applyBuiltPrerenderInvalidations(\n options.runtime,\n response,\n options.prerenderStore,\n );\n\n return options.sinkStrategy === \"buffer\"\n ? await materializeResponseAsBuffer(response)\n : response;\n}\n\nasync function resolveBuiltMiddleware(\n options: RenderBuiltAppRequestOptions & {\n runtime: BuiltRuntime;\n timing?: { phases: Record<string, number> } | undefined;\n },\n request: Request,\n): Promise<{ request: Request; type: \"continue\" } | { response: Response; type: \"response\" }> {\n if (!options.runtime.hasMiddleware) {\n return { request, type: \"continue\" };\n }\n\n await loadBuiltServerModuleArtifactsForRequest(options.runtime, undefined);\n\n return resolveAppRouterMiddleware({\n appDir: options.runtime.appDir,\n importPolicy: {\n ...options.importPolicy,\n allowedSourceDirs: options.runtime.allowedSourceDirs,\n projectRoot: options.runtime.projectRoot,\n },\n instrumentation: options.instrumentation,\n request,\n serverModules: options.runtime.serverModules,\n serverModuleCacheVersion: options.runtime.serverModuleCacheVersion,\n serverSourceFiles: options.runtime.serverSourceFiles,\n timing: options.timing,\n });\n}\n\nfunction createBuiltRenderTiming(\n logger: AppRouterLogger | undefined,\n): { phases: Record<string, number> } | undefined {\n return logger?.debug === undefined ? undefined : { phases: {} };\n}\n\nfunction builtRenderTimingPhaseStartedAt(\n timing: { phases: Record<string, number> } | undefined,\n): number | undefined {\n return timing === undefined ? undefined : logNow();\n}\n\nfunction finishBuiltRenderTimingPhase(\n timing: { phases: Record<string, number> } | undefined,\n startedAt: number | undefined,\n phaseName: string,\n): void {\n if (timing === undefined || startedAt === undefined) {\n return;\n }\n\n timing.phases[phaseName] = logDurationMs(startedAt);\n}\n\nfunction emitBuiltRenderTiming(\n options: RenderBuiltAppRequestOptions,\n request: Request,\n timing: { phases: Record<string, number> } | undefined,\n status: number,\n): void {\n if (timing === undefined) {\n return;\n }\n\n emitRouterLog(options.logger, \"debug\", {\n method: request.method,\n path: new URL(request.url).pathname,\n phases: timing.phases,\n status,\n type: \"router:render:timing\",\n });\n}\n\nasync function applyBuiltAppResponseHook(\n response: Response,\n options: Pick<RenderBuiltAppRequestOptions, \"onResponse\" | \"request\">,\n runtime: BuiltRuntime,\n): Promise<Response> {\n await loadBuiltResponseHookArtifacts(runtime);\n const onResponse = await resolveAppRouterResponseHook({\n appDir: runtime.appDir,\n importPolicy: runtime.generatedImportPolicy,\n onResponse: options.onResponse,\n serverModules: runtime.serverModules,\n serverModuleCacheVersion: runtime.serverModuleCacheVersion,\n serverSourceFiles: runtime.serverSourceFiles,\n });\n const hooked = await onResponse?.(response, {\n request: options.request,\n });\n\n return hooked instanceof Response ? hooked : response;\n}\n\nasync function materializeResponseAsBuffer(response: Response): Promise<Response> {\n if (response.body === null) {\n return response;\n }\n\n // Drains streaming responses into a single Buffer (loses TTFB streaming\n // by design — opt-in via sinkStrategy === \"buffer\"). Avoids the\n // string → UTF-8 encode the Response stream would otherwise do lazily\n // during the socket write. Tagged via `bytesResponse` so `sendResponse`\n // can take the raw-bytes fast path.\n const bytes = new Uint8Array(await response.arrayBuffer());\n return bytesResponse(bytes, {\n headers: response.headers,\n status: response.status,\n statusText: response.statusText,\n });\n}\n\n/**\n * Starts a Node HTTP server for an already built app-router output directory.\n *\n * Use this for production-like local serving or custom Node deployments. It loads `.mreact/server` artifacts, applies the generated import policy when configured, enforces host trust options, and returns a `close()` method for orderly shutdown.\n */\nexport async function startServer(\n options: StartServerOptions,\n): Promise<{ close(): Promise<void>; server: Server; url: string }> {\n warnIfImplicitHostTrust(options);\n const runtime = await createBuiltRequestRuntime({\n importPolicy: options.importPolicy,\n outDir: options.outDir,\n });\n\n return await startNodeRequestServer({\n allowedHosts: options.allowedHosts,\n errorHandler: options.errorHandler,\n hostname: options.hostname,\n hostPolicy: options.hostPolicy,\n logger: options.logger,\n onUpgrade: options.onUpgrade,\n port: options.port,\n resolveHost: resolveRequestHost,\n render: (request) =>\n runtime.render(request, {\n instrumentation: options.instrumentation,\n logger: options.logger,\n onResponse: options.onResponse,\n prerenderStore: options.prerenderStore,\n routeCache: options.routeCache,\n serverActions: options.serverActions,\n ...(options.sinkStrategy === undefined ? {} : { sinkStrategy: options.sinkStrategy }),\n }),\n });\n}\n\nexport const __readBuiltPublicAssetForTest = readBuiltPublicAsset;\n\nexport function __clearBuiltRuntimeCacheForTest(): void {\n builtRuntimeCache.clear();\n builtRuntimeReadInflight.clear();\n builtRuntimeMaterializeCountForTest = 0;\n}\n\nexport function __getBuiltRuntimeMaterializeCountForTest(): number {\n return builtRuntimeMaterializeCountForTest;\n}\n\nexport function __clearBuiltPublicAssetCacheForTest(): void {\n clearBuiltPublicAssetCacheForTest();\n}\n\nexport function __getBuiltPublicAssetCacheSizeForTest(): number {\n return getBuiltPublicAssetCacheSizeForTest();\n}\n\nasync function readBuiltRuntime(options: {\n immutable?: boolean | undefined;\n outDir: string;\n runtimeDir?: string | undefined;\n}): Promise<BuiltRuntime> {\n const outDir = options.outDir;\n const runtimeDir = options.runtimeDir ?? join(outDir, \"server\", \"runtime\");\n const cacheKey = `${outDir}\\0${runtimeDir}`;\n const cached = builtRuntimeCache.get(cacheKey);\n\n if (options.immutable === true && cached !== undefined) {\n return cached.runtime;\n }\n\n if (cached === undefined) {\n const inflight = builtRuntimeReadInflight.get(cacheKey);\n if (inflight !== undefined) {\n return inflight;\n }\n\n const runtime = readBuiltRuntimeUncached({\n cacheKey,\n cached,\n outDir,\n runtimeDir,\n });\n builtRuntimeReadInflight.set(cacheKey, runtime);\n void runtime\n .finally(() => {\n if (builtRuntimeReadInflight.get(cacheKey) === runtime) {\n builtRuntimeReadInflight.delete(cacheKey);\n }\n })\n .catch(() => {});\n return runtime;\n }\n\n return readBuiltRuntimeUncached({\n cacheKey,\n cached,\n outDir,\n runtimeDir,\n });\n}\n\nasync function readBuiltRuntimeUncached(options: {\n cached: BuiltRuntimeCacheEntry | undefined;\n cacheKey: string;\n outDir: string;\n runtimeDir: string;\n}): Promise<BuiltRuntime> {\n const { cacheKey, cached, outDir, runtimeDir } = options;\n const serverManifestPath = join(outDir, \"server\", \"manifest.json\");\n const clientManifestPath = join(outDir, \"client\", \"manifest.json\");\n const importPolicyPath = join(outDir, \"server\", \"import-policy.json\");\n const [serverManifestText, clientManifestText, importPolicyText] = await Promise.all([\n readRequiredBuiltArtifactText(serverManifestPath, \"built app server manifest\"),\n readRequiredBuiltArtifactText(clientManifestPath, \"built app client manifest\"),\n readBuiltImportPolicyText(outDir),\n ]);\n\n if (\n cached !== undefined &&\n cached.serverManifestText === serverManifestText &&\n cached.clientManifestText === clientManifestText &&\n cached.importPolicyText === importPolicyText\n ) {\n return cached.runtime;\n }\n\n const runtime = materializeBuiltRuntime({\n clientManifestText,\n clientManifestPath,\n importPolicyText,\n importPolicyPath,\n onMaterialize() {\n builtRuntimeMaterializeCountForTest += 1;\n },\n outDir,\n runtimeDir,\n serverManifestText,\n serverManifestPath,\n });\n\n builtRuntimeCache.set(cacheKey, {\n clientManifestText,\n importPolicyText,\n runtime,\n serverManifestText,\n });\n runtime.catch(() => {\n if (builtRuntimeCache.get(cacheKey)?.runtime === runtime) {\n builtRuntimeCache.delete(cacheKey);\n }\n });\n\n return runtime;\n}\n\nfunction isMissingFileError(error: unknown): boolean {\n return (\n typeof error === \"object\" &&\n error !== null &&\n \"code\" in error &&\n (error as { code?: unknown }).code === \"ENOENT\"\n );\n}\n\nasync function readRequiredBuiltArtifactText(labelPath: string, label: string): Promise<string> {\n try {\n return await readFile(labelPath, \"utf8\");\n } catch (error) {\n throw builtArtifactReadError(label, labelPath, error);\n }\n}\n\nfunction builtArtifactReadError(label: string, artifactPath: string, error: unknown): Error {\n const prefix = isMissingFileError(error) ? \"Missing\" : \"Unable to read\";\n const detail = error instanceof Error && error.message !== \"\" ? `: ${error.message}` : \"\";\n\n return new Error(`${prefix} ${label}: ${artifactPath}${detail}`, { cause: error });\n}\n\nasync function readPrerenderedRoute(\n runtime: BuiltRuntime,\n path: string,\n store: AppRouterPrerenderStore | undefined,\n): Promise<BuiltPrerenderedRoute | undefined> {\n const stored = await store?.get(path);\n\n if (stored !== undefined) {\n runtime.prerenderedRoutes.set(path, stored);\n return stored;\n }\n\n const manifestEntry = runtime.prerenderedRoutes.get(path);\n\n if (manifestEntry !== undefined && store !== undefined) {\n await store.set(path, manifestEntry);\n }\n\n return manifestEntry;\n}\n\nfunction renderBuiltDynamicResponse(\n options: RenderBuiltAppRequestOptions & {\n matchedRoute?: MatchedRoute | undefined;\n requestUrl?: URL | undefined;\n runtime: BuiltRuntime;\n },\n): Promise<Response> {\n return renderAppRequest(builtRenderAppRequestOptions(options));\n}\n\nfunction builtRenderAppRequestOptions(\n options: RenderBuiltAppRequestOptions & {\n matchedRoute?: MatchedRoute | undefined;\n requestUrl?: URL | undefined;\n runtime: BuiltRuntime;\n },\n): RenderAppRequestRuntimeOptions {\n const serverRenderArtifactLoader: AppRouterServerRenderArtifactLoader = {\n async load(routeFile: string) {\n await loadBuiltServerModuleArtifactsForRequest(options.runtime, routeFile, {\n includeRender: true,\n });\n },\n };\n const renderOptions: RenderAppRequestRuntimeOptions = {\n appDir: options.runtime.appDir,\n assetBaseUrl: options.runtime.assetBaseUrl,\n clientScripts: options.runtime.clientScripts,\n clientStylesByFile: options.runtime.clientStylesByFile,\n clientStyles: options.runtime.clientStyles,\n importPolicy: {\n ...options.importPolicy,\n allowedSourceDirs: options.runtime.allowedSourceDirs,\n projectRoot: options.runtime.projectRoot,\n },\n request: options.request,\n instrumentation: options.instrumentation,\n logger: options.logger,\n matchedRoute: options.matchedRoute,\n navigationScripts: options.runtime.navigationScripts,\n routeCache: options.routeCache,\n routeMatcher: options.runtime.routeMatcher,\n requestUrl: options.requestUrl,\n routes: options.runtime.routes,\n serverRenderArtifactLoader,\n serverModules: options.runtime.serverModules,\n serverModuleCacheVersion: options.runtime.serverModuleCacheVersion,\n serverSourceFiles: options.runtime.serverSourceFiles,\n serverActionReferencesByFile: options.runtime.serverActionReferencesByFile,\n serverActions: mergeBuiltServerActionOptions(\n options.serverActions,\n options.runtime.serverActionManifest,\n ),\n skipMiddleware: true,\n onResponse: () => undefined,\n ...(options.preload === undefined ? {} : { preload: options.preload }),\n };\n\n return renderOptions;\n}\n\nfunction mergeBuiltServerActionOptions(\n options: AppRouterServerActionOptions | undefined,\n allowedActions: readonly { moduleId: string; exportName: string; inferred?: boolean }[] | undefined,\n): AppRouterServerActionOptions | undefined {\n if (allowedActions === undefined) {\n return options;\n }\n\n return {\n ...options,\n allowedActions,\n };\n}\n\nasync function renderAndCachePrerenderWithLock(\n options: RenderBuiltAppRequestOptions & { runtime: BuiltRuntime },\n path: string,\n): Promise<Response> {\n const existing = options.runtime.prerenderLocks.get(path);\n\n if (existing !== undefined) {\n return cloneResponse(await existing);\n }\n\n const task = runPrerenderRegeneration(options, path);\n options.runtime.prerenderLocks.set(path, task);\n\n try {\n return cloneResponse(await task);\n } finally {\n options.runtime.prerenderLocks.delete(path);\n }\n}\n\nasync function runPrerenderRegeneration(\n options: RenderBuiltAppRequestOptions & { runtime: BuiltRuntime },\n path: string,\n): Promise<Response> {\n const regenerate = async () => {\n const stored = await readPrerenderedRoute(options.runtime, path, options.prerenderStore);\n\n if (stored !== undefined) {\n return htmlResponse(stored.html, {\n headers: stored.headers,\n status: stored.status,\n });\n }\n\n const response = await renderBuiltDynamicResponse(options);\n\n return response.ok\n ? await cacheRegeneratedPrerenderedRoute(\n options.runtime,\n path,\n response,\n options.prerenderStore,\n )\n : response;\n };\n\n return options.prerenderStore?.withLock === undefined\n ? await regenerate()\n : await options.prerenderStore.withLock(path, regenerate);\n}\n\nasync function applyBuiltPrerenderInvalidations(\n runtime: BuiltRuntime,\n response: Response,\n store: AppRouterPrerenderStore | undefined,\n): Promise<void> {\n const revalidated = response.headers.get(\"x-mreact-revalidate\");\n\n if (revalidated === null) {\n return;\n }\n\n for (const path of revalidated.split(\",\")) {\n const normalized = normalizeRoutePath(path.trim());\n runtime.prerenderedRoutes.delete(normalized);\n await store?.delete(normalized);\n }\n}\n\nasync function cacheRegeneratedPrerenderedRoute(\n runtime: BuiltRuntime,\n path: string,\n response: Response,\n store: AppRouterPrerenderStore | undefined,\n): Promise<Response> {\n const body = await response.text();\n const headers: Record<string, string> = {};\n\n response.headers.forEach((value, key) => {\n headers[key] = value;\n });\n const entry = {\n headers,\n html: body,\n status: response.status,\n };\n runtime.prerenderedRoutes.set(path, entry);\n await store?.set(path, entry);\n\n return htmlResponse(body, {\n headers: response.headers,\n status: response.status,\n });\n}\n\nasync function cloneResponse(response: Response): Promise<Response> {\n return htmlResponse(await response.clone().text(), {\n headers: response.headers,\n status: response.status,\n });\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"vite.d.ts","sourceRoot":"","sources":["../src/vite.ts"],"names":[],"mappings":"AAQA,OAAO,EAEL,KAA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SAAS,YAAY,EAAE,GAAG,SAAS,CAAA;CAAO,GACjF,OAAO,CAAC,QAAQ,CAAC,CAgFnB"}
package/dist/vite.js CHANGED
@@ -164,6 +164,7 @@ export function createAppRouterVitePlugin(options) {
164
164
  },
165
165
  configureServer(server) {
166
166
  server.middlewares.use(createDevCssProxyMiddleware());
167
+ server.middlewares.use(createClientRouteTransformMiddleware(project.routesDir, server));
167
168
  return () => {
168
169
  const middlewareOptions = {
169
170
  ...options,
@@ -301,6 +302,36 @@ export function prepareReactiveEffectRunDevtoolsEvent() { return undefined; }`;
301
302
  };
302
303
  return plugin;
303
304
  }
305
+ function createClientRouteTransformMiddleware(appDir, server) {
306
+ return (request, response, next) => {
307
+ void (async () => {
308
+ const url = new URL(request.url ?? "/", "http://localhost");
309
+ if (!url.pathname.startsWith(`${clientPrefix}routes/`)) {
310
+ next();
311
+ return;
312
+ }
313
+ const route = await clientRouteForRequestPath(appDir, url.pathname);
314
+ if (route === undefined) {
315
+ next();
316
+ return;
317
+ }
318
+ try {
319
+ const transformed = await server.transformRequest(`${url.pathname}${url.search}`);
320
+ if (transformed === null) {
321
+ next();
322
+ return;
323
+ }
324
+ await sendResponse(response, new Response(transformed.code, {
325
+ headers: { "content-type": "text/javascript; charset=utf-8" },
326
+ }));
327
+ }
328
+ catch (error) {
329
+ sendViteErrorOverlay(server, error);
330
+ await sendResponse(response, clientAssetBuildErrorResponse(route.file, error));
331
+ }
332
+ })().catch(next);
333
+ };
334
+ }
304
335
  function isMreactClientSourceDependency(filename, normalizedSourceDirs) {
305
336
  const normalized = normalizePath(filename);
306
337
  return (/\.(?:mreact\.)?[cm]?[jt]sx?$/.test(normalized) &&