diff --git a/.changeset/mighty-icons-arrive.md b/.changeset/mighty-icons-arrive.md new file mode 100644 index 000000000000..925f3dbca97f --- /dev/null +++ b/.changeset/mighty-icons-arrive.md @@ -0,0 +1,6 @@ +--- +'@modern-js/prod-server': minor +--- + +feat: add forceCSR options for worker server +feat: 在 worker server 新增 forceCSR 参数和判断 csr=1 降级 diff --git a/packages/server/prod-server/src/workerServer.ts b/packages/server/prod-server/src/workerServer.ts index ef9cb06f0556..1e078ef0a8dd 100644 --- a/packages/server/prod-server/src/workerServer.ts +++ b/packages/server/prod-server/src/workerServer.ts @@ -102,6 +102,9 @@ export type Manifest = { */ pages: Record; routes: ModernRouteInterface[]; + options?: { + forceCSR?: boolean; + }; }; const RESPONSE_NOTFOUND = new ReturnResponse('404: Page not found', 404); @@ -126,7 +129,7 @@ const middlewarePipeline = createAsyncPipeline< export const createHandler = (manifest: Manifest) => { const routeMgr = new RouteMatchManager(); - const { pages, routes } = manifest; + const { pages, routes, options: manifestOpts = {} } = manifest; routeMgr.reset(routes); return async (options: HandlerOptions): Promise => { const { request, loadableStats, routeManifest } = options; @@ -139,6 +142,10 @@ export const createHandler = (manifest: Manifest) => { const entryName = pageMatch.spec.urlPath; const page = pages[entryName]; + if (manifestOpts.forceCSR && url.searchParams.get('csr') === '1') { + return createResponse(page.template); + } + const logger = createLogger({ level: 'warn' }); const metrics = defaultMetrics as any; const reporter = defaultReporter;