From a68a2e9a8043f6908975f3b0f25d82caff2c1f9a Mon Sep 17 00:00:00 2001 From: qixuan <58852732+GiveMe-A-Name@users.noreply.github.com> Date: Mon, 6 Nov 2023 14:58:49 +0800 Subject: [PATCH] fix(prod-server): inject reporter from req (#4919) --- .changeset/unlucky-adults-stare.md | 6 ++++++ packages/server/prod-server/src/libs/context/context.ts | 3 +++ packages/server/prod-server/src/type.ts | 2 ++ 3 files changed, 11 insertions(+) create mode 100644 .changeset/unlucky-adults-stare.md diff --git a/.changeset/unlucky-adults-stare.md b/.changeset/unlucky-adults-stare.md new file mode 100644 index 000000000000..2fbd9af4cf57 --- /dev/null +++ b/.changeset/unlucky-adults-stare.md @@ -0,0 +1,6 @@ +--- +'@modern-js/prod-server': patch +--- + +fix(prod-server): inject reporter from req +fix(prod-server): 从 req 里拿到 reporter 去注入 diff --git a/packages/server/prod-server/src/libs/context/context.ts b/packages/server/prod-server/src/libs/context/context.ts index 53d96217e595..1af1631a5c8a 100644 --- a/packages/server/prod-server/src/libs/context/context.ts +++ b/packages/server/prod-server/src/libs/context/context.ts @@ -74,6 +74,9 @@ export class ModernServerContext implements ModernServerContextInterface { this.res, cutNameByHyphen(options?.metaName || 'modern-js'), ); + + // inject reporter from req if it has. + req.reporter && (this.reporter = req.reporter); } private get parsedURL() { diff --git a/packages/server/prod-server/src/type.ts b/packages/server/prod-server/src/type.ts index 154fb5711afd..bc33d59c0968 100644 --- a/packages/server/prod-server/src/type.ts +++ b/packages/server/prod-server/src/type.ts @@ -9,6 +9,7 @@ import type { NextFunction, ModernServerContext, InternalPlugins, + Reporter, } from '@modern-js/types'; import type { ModernRouteInterface } from './libs/route'; @@ -16,6 +17,7 @@ declare module 'http' { interface IncomingMessage { logger: Logger; metrics: Metrics; + reporter?: Reporter; body?: any; }