Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add forceCSR for worker server #4923

Merged
merged 2 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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