Skip to content

Commit a463551

Browse files
committed
feat(server-time): enhance middleware configuration and import context
- Updated server-time middleware to import RequestContext for improved request handling. - Modified ServerTimeModule to conditionally apply middleware based on the environment, using apiRoutePrefix for production paths. - Adjusted snapshot tests to reflect changes in the note controller's response structure, adding is_published field. Signed-off-by: Innei <[email protected]>
1 parent 0a8ab1e commit a463551

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

apps/core/src/modules/server-time/server-time.middleware.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import type { IncomingMessage, ServerResponse } from 'node:http'
22

3+
import { RequestContext } from '~/common/contexts/request.context'
4+
35
export async function trackResponseTimeMiddleware(
46
req: IncomingMessage,
57
res: ServerResponse,

apps/core/src/modules/server-time/server-time.module.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import type { MiddlewareConsumer, NestModule } from '@nestjs/common'
22

33
import { Module, RequestMethod } from '@nestjs/common'
44

5+
import { apiRoutePrefix } from '~/common/decorators/api-controller.decorator'
6+
57
import { ServerTimeController } from './server-time.controller'
68
import { trackResponseTimeMiddleware } from './server-time.middleware'
79

@@ -10,8 +12,9 @@ import { trackResponseTimeMiddleware } from './server-time.middleware'
1012
})
1113
export class ServerTimeModule implements NestModule {
1214
configure(consumer: MiddlewareConsumer) {
13-
consumer
14-
.apply(trackResponseTimeMiddleware)
15-
.forRoutes({ path: '/server-time', method: RequestMethod.ALL })
15+
consumer.apply(trackResponseTimeMiddleware).forRoutes({
16+
path: isDev ? '/server-time' : `${apiRoutePrefix}/server-time`,
17+
method: RequestMethod.ALL,
18+
})
1619
}
1720
}

apps/core/test/src/modules/note/__snapshots__/note.controller.e2e-spec.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ exports[`NoteController (e2e) > GET /latest 1`] = `
1111
"read": 0,
1212
},
1313
"created": "2021-03-20T00:00:00.000Z",
14-
"hide": false,
1514
"images": [],
15+
"is_published": true,
1616
"modified": null,
1717
"nid": 20,
1818
"text": "Content 20",

0 commit comments

Comments
 (0)