()
| 491 | } |
| 492 | |
| 493 | public getRequestHandler(): NodeRequestHandler { |
| 494 | const handler = super.getRequestHandler() |
| 495 | |
| 496 | return (req, res, parsedUrl) => { |
| 497 | const request = this.normalizeReq(req) |
| 498 | const response = this.normalizeRes(res) |
| 499 | const loggingConfig = this.nextConfig.logging |
| 500 | |
| 501 | if (loggingConfig !== false) { |
| 502 | // The closure variable is not used here because the request handler may be invoked twice for one request when middleware is added in the application. |
| 503 | // By setting the start time we can ensure that the middleware timing is correctly included. |
| 504 | if (!getRequestMeta(req, 'devRequestTimingStart')) { |
| 505 | const requestStart = process.hrtime.bigint() |
| 506 | addRequestMeta(req, 'devRequestTimingStart', requestStart) |
| 507 | } |
| 508 | const isMiddlewareRequest = |
| 509 | getRequestMeta(req, 'middlewareInvoke') ?? false |
| 510 | |
| 511 | if (!isMiddlewareRequest) { |
| 512 | response.originalResponse.once('close', () => { |
| 513 | // NOTE: The route match is only attached to the request's meta data |
| 514 | // after the request handler is created, so we need to check it in the |
| 515 | // close handler and not before. |
| 516 | const routeMatch = getRequestMeta(req).match |
| 517 | |
| 518 | if (!routeMatch) { |
| 519 | return |
| 520 | } |
| 521 | |
| 522 | // The closure variable is not used here because the request handler may be invoked twice for one request when middleware is added in the application. |
| 523 | // By setting the start time we can ensure that the middleware timing is correctly included. |
| 524 | const requestStart = getRequestMeta(req, 'devRequestTimingStart') |
| 525 | if (!requestStart) { |
| 526 | return |
| 527 | } |
| 528 | const requestEnd = process.hrtime.bigint() |
| 529 | logRequests( |
| 530 | request, |
| 531 | response, |
| 532 | loggingConfig, |
| 533 | requestStart, |
| 534 | requestEnd, |
| 535 | getRequestMeta(req, 'devRequestTimingMiddlewareStart'), |
| 536 | getRequestMeta(req, 'devRequestTimingMiddlewareEnd'), |
| 537 | getRequestMeta(req, 'devRequestTimingInternalsEnd'), |
| 538 | getRequestMeta(req, 'devGenerateStaticParamsDuration') |
| 539 | ) |
| 540 | |
| 541 | // Create trace span for render phase |
| 542 | const devRequestTimingInternalsEnd = getRequestMeta( |
| 543 | req, |
| 544 | 'devRequestTimingInternalsEnd' |
| 545 | ) |
| 546 | if (devRequestTimingInternalsEnd) { |
| 547 | this.startServerSpan.manualTraceChild( |
| 548 | 'render-path', |
| 549 | hrtimeToEpochNanoseconds(devRequestTimingInternalsEnd), |
| 550 | hrtimeToEpochNanoseconds(requestEnd), |
nothing calls this directly
no test coverage detected