Skip to content

Commit

Permalink
fix: export reporter only in middlewares-context (#4562)
Browse files Browse the repository at this point in the history
  • Loading branch information
GiveMe-A-Name authored Oct 20, 2023
1 parent f5beac5 commit 6d8ef7d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .changeset/loud-garlics-thank.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@modern-js/prod-server': patch
---

fix: export reporter only in middlewares-context
fix: 只在 middlewares-context 导出 reporter
4 changes: 2 additions & 2 deletions packages/server/prod-server/src/libs/hook-api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ import { TemplateAPI } from './template';
import { BaseRequest, BaseResponse } from './base';

export const base = (context: ModernServerContext): HookContext => {
const { res, reporter } = context;
const { res } = context;

return {
response: new BaseResponse(res),
request: new BaseRequest(context),
reporter,
logger: context.logger,
metrics: context.metrics,
};
Expand Down Expand Up @@ -51,6 +50,7 @@ export const createMiddlewareContext = (
return {
...baseContext,
response: baseContext.response as any,
reporter: context.reporter,
source: {
req: context.req,
res: context.res,
Expand Down
4 changes: 2 additions & 2 deletions packages/server/prod-server/src/libs/hook-api/index.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class ServerResponse implements ServerResponseLike {
}

export const base = (context: WorkerServerContext): HookContext => {
const { req, res, logger, metrics, reporter } = context;
const { req, res, logger, metrics } = context;
const serverResponse = new ServerResponse(res);

// eslint-disable-next-line node/no-unsupported-features/node-builtins, node/prefer-global/url
Expand All @@ -77,7 +77,6 @@ export const base = (context: WorkerServerContext): HookContext => {

return {
response: new BaseResponse(serverResponse),
reporter,
request: new BaseRequest({
url: req.url,
host,
Expand Down Expand Up @@ -127,6 +126,7 @@ export const createMiddlewareContext = (

return {
...baseContext,
reporter: context.reporter,
response: baseContext.response as any,
source: {
req: rawRequest,
Expand Down
2 changes: 1 addition & 1 deletion packages/toolkit/types/server/hook.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export type HookContext = {
response: ModernResponse;
request: ModernRequest;
logger: Logger;
reporter?: Reporter;
metrics?: Metrics;
};

Expand Down Expand Up @@ -64,6 +63,7 @@ export type AfterRenderContext = HookContext & {

export type MiddlewareContext<T extends 'worker' | 'node' = 'node'> =
HookContext & {
reporter?: Reporter;
response: ModernResponse & { locals: Record<string, any> };
source: {
req: T extends 'worker' ? Request : IncomingMessage;
Expand Down

0 comments on commit 6d8ef7d

Please sign in to comment.