Skip to content

Commit

Permalink
fix(worker-server): rslogger can't work in worker env (#5014)
Browse files Browse the repository at this point in the history
  • Loading branch information
GiveMe-A-Name authored Nov 29, 2023
1 parent 460e45c commit 8793e64
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changeset/silent-pianos-unite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@modern-js/prod-server': patch
---

fix(worker-server): rslogger can't work in worker env.
fix(worker-server): rslogger 在 worker 环境不能正常工作.
25 changes: 22 additions & 3 deletions packages/server/prod-server/src/workerServer.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {
import type {
AfterMatchContext,
AfterRenderContext,
BaseSSRServerContext,
Logger,
MiddlewareContext,
NextFunction,
Reporter,
} from '@modern-js/types';
import { createAsyncPipeline } from '@modern-js/plugin';
import { createLogger } from '@modern-js/utils/logger';
import {
WorkerServerContext,
createAfterMatchContext,
Expand All @@ -18,6 +18,25 @@ import { ModernRouteInterface, RouteMatchManager } from './libs/route';
import { metrics as defaultMetrics } from './libs/metrics';
import { defaultReporter } from './libs/reporter';

// TODO: inject logger from worker
const createLogger = (): Logger => ({
error(message, ...args: any[]) {
console.error(message, ...args);
},
info(message, ...args: any[]) {
console.error(message, ...args);
},
warn(message, ...args: any[]) {
console.warn(message, ...args);
},
debug(message, ...args: any[]) {
console.debug(message, ...args);
},
log(message, ...args: any[]) {
console.log(message, ...args);
},
});

const calcFallback = (metaName: string) =>
`x-${metaName.split(/[-_]/)[0]}-ssr-fallback`;

Expand Down Expand Up @@ -151,7 +170,7 @@ export const createHandler = (manifest: Manifest) => {
return createResponse(page.template);
}

const logger = createLogger({ level: 'warn' });
const logger = createLogger();
const metrics = defaultMetrics as any;
const reporter = defaultReporter;
const route = pageMatch.generate(url.pathname);
Expand Down

0 comments on commit 8793e64

Please sign in to comment.