|
1 | 1 | import type { NextApiResponse } from '../../types'
|
2 | 2 | import type { IncomingMessage, ServerResponse } from 'node:http'
|
| 3 | +import type { PrerenderManifest } from '..' |
| 4 | +import type { DevRoutesManifest } from '../../server/lib/router-utils/setup-dev-bundler' |
| 5 | +import type { InstrumentationOnRequestError } from '../../server/instrumentation/types' |
3 | 6 |
|
4 | 7 | import { parse } from 'node:url'
|
5 |
| -import { RouteKind } from '../../server/route-kind' |
6 | 8 | import { sendError } from '../../server/api-utils'
|
| 9 | +import { RouteKind } from '../../server/route-kind' |
| 10 | +import type { Span } from '../../server/lib/trace/tracer' |
| 11 | +import type { BaseNextRequest } from '../../server/base-http' |
7 | 12 | import { PagesAPIRouteModule } from '../../server/route-modules/pages-api/module.compiled'
|
8 | 13 |
|
9 | 14 | import { hoist } from './helpers'
|
10 | 15 |
|
11 | 16 | // Import the userland code.
|
12 | 17 | import * as userland from 'VAR_USERLAND'
|
13 | 18 | import { getTracer, SpanKind } from '../../server/lib/trace/tracer'
|
14 |
| -import type { Span } from '../../server/lib/trace/tracer' |
15 | 19 | import { BaseServerSpan } from '../../server/lib/trace/constants'
|
16 | 20 | import {
|
17 | 21 | ensureInstrumentationRegistered,
|
18 | 22 | instrumentationOnRequestError,
|
19 | 23 | } from '../../server/lib/router-utils/instrumentation-globals.external'
|
20 |
| -import type { InstrumentationOnRequestError } from '../../server/instrumentation/types' |
21 | 24 | import { getUtils } from '../../server/server-utils'
|
22 | 25 | import { PRERENDER_MANIFEST, ROUTES_MANIFEST } from '../../api/constants'
|
23 | 26 | import { isDynamicRoute } from '../../shared/lib/router/utils'
|
24 |
| -import type { BaseNextRequest } from '../../server/base-http' |
25 | 27 | import {
|
26 | 28 | RouterServerContextSymbol,
|
27 | 29 | routerServerGlobal,
|
28 | 30 | } from '../../server/lib/router-utils/router-server-context'
|
29 | 31 | import { removePathPrefix } from '../../shared/lib/router/utils/remove-path-prefix'
|
30 | 32 | import { normalizeLocalePath } from '../../shared/lib/i18n/normalize-locale-path'
|
31 |
| -import type { PrerenderManifest, RoutesManifest } from '..' |
32 | 33 | import { loadManifestFromRelativePath } from '../../server/load-manifest.external'
|
33 | 34 |
|
34 | 35 | // Re-export the handler (should be the default export).
|
@@ -62,17 +63,18 @@ export async function handler(
|
62 | 63 | const distDir = process.env.__NEXT_RELATIVE_DIST_DIR || ''
|
63 | 64 | const isDev = process.env.NODE_ENV === 'development'
|
64 | 65 |
|
65 |
| - const routesManifest = await loadManifestFromRelativePath<RoutesManifest>( |
66 |
| - projectDir, |
67 |
| - distDir, |
68 |
| - ROUTES_MANIFEST |
69 |
| - ) |
70 |
| - const prerenderManifest = |
71 |
| - await loadManifestFromRelativePath<PrerenderManifest>( |
| 66 | + const [routesManifest, prerenderManifest] = await Promise.all([ |
| 67 | + loadManifestFromRelativePath<DevRoutesManifest>( |
| 68 | + projectDir, |
| 69 | + distDir, |
| 70 | + ROUTES_MANIFEST |
| 71 | + ), |
| 72 | + loadManifestFromRelativePath<PrerenderManifest>( |
72 | 73 | projectDir,
|
73 | 74 | distDir,
|
74 | 75 | PRERENDER_MANIFEST
|
75 |
| - ) |
| 76 | + ), |
| 77 | + ]) |
76 | 78 | let srcPage = 'VAR_DEFINITION_PAGE'
|
77 | 79 |
|
78 | 80 | // turbopack doesn't normalize `/index` in the page name
|
@@ -114,7 +116,7 @@ export async function handler(
|
114 | 116 | caseSensitive: Boolean(routesManifest.caseSensitive),
|
115 | 117 | })
|
116 | 118 | const rewriteParamKeys = Object.keys(
|
117 |
| - serverUtils.handleRewrites(req as any as BaseNextRequest, parsedUrl) |
| 119 | + serverUtils.handleRewrites(req, parsedUrl) |
118 | 120 | )
|
119 | 121 | serverUtils.normalizeCdnUrl(req as any as BaseNextRequest, [
|
120 | 122 | ...rewriteParamKeys,
|
@@ -150,8 +152,8 @@ export async function handler(
|
150 | 152 |
|
151 | 153 | const activeSpan = tracer.getActiveScopeSpan()
|
152 | 154 |
|
153 |
| - const invokeRouteModule = async (span?: Span) => { |
154 |
| - await routeModule |
| 155 | + const invokeRouteModule = async (span?: Span) => |
| 156 | + routeModule |
155 | 157 | .render(req, res, {
|
156 | 158 | query,
|
157 | 159 | params,
|
@@ -210,7 +212,6 @@ export async function handler(
|
210 | 212 | span.updateName(`${method} ${req.url}`)
|
211 | 213 | }
|
212 | 214 | })
|
213 |
| - } |
214 | 215 |
|
215 | 216 | // TODO: activeSpan code path is for when wrapped by
|
216 | 217 | // next-server can be removed when this is no longer used
|
|
0 commit comments