Skip to content

Commit

Permalink
feat: add forceCSR for worker server (#4923)
Browse files Browse the repository at this point in the history
  • Loading branch information
spencerHT authored Nov 7, 2023
1 parent 7555827 commit c960bcb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/mighty-icons-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@modern-js/prod-server': minor
---

feat: add forceCSR options for worker server
feat: 在 worker server 新增 forceCSR 参数和判断 csr=1 降级
9 changes: 8 additions & 1 deletion packages/server/prod-server/src/workerServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ export type Manifest = {
*/
pages: Record<string, Page>;
routes: ModernRouteInterface[];
options?: {
forceCSR?: boolean;
};
};

const RESPONSE_NOTFOUND = new ReturnResponse('404: Page not found', 404);
Expand All @@ -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<ReturnResponse> => {
const { request, loadableStats, routeManifest } = options;
Expand All @@ -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;
Expand Down

0 comments on commit c960bcb

Please sign in to comment.