(
parsedUrl: NextUrlWithParsedQuery,
invokePath: string,
handleIndex: number,
additionalRequestMeta?: RequestMeta
)
| 296 | const invokedOutputs = new Set<string>() |
| 297 | |
| 298 | async function invokeRender( |
| 299 | parsedUrl: NextUrlWithParsedQuery, |
| 300 | invokePath: string, |
| 301 | handleIndex: number, |
| 302 | additionalRequestMeta?: RequestMeta |
| 303 | ) { |
| 304 | // invokeRender expects /api routes to not be locale prefixed |
| 305 | // so normalize here before continuing |
| 306 | if ( |
| 307 | config.i18n && |
| 308 | removePathPrefix(invokePath, config.basePath).startsWith( |
| 309 | `/${getRequestMeta(req, 'locale')}/api` |
| 310 | ) |
| 311 | ) { |
| 312 | invokePath = fsChecker.handleLocale( |
| 313 | removePathPrefix(invokePath, config.basePath) |
| 314 | ).pathname |
| 315 | } |
| 316 | |
| 317 | if ( |
| 318 | req.headers['x-nextjs-data'] && |
| 319 | fsChecker.getMiddlewareMatchers()?.length && |
| 320 | removePathPrefix(invokePath, config.basePath) === '/404' |
| 321 | ) { |
| 322 | res.setHeader('x-nextjs-matched-path', parsedUrl.pathname || '') |
| 323 | res.statusCode = 404 |
| 324 | res.setHeader('content-type', 'application/json') |
| 325 | res.end('{}') |
| 326 | return null |
| 327 | } |
| 328 | |
| 329 | if (!handlers) { |
| 330 | throw new Error('Failed to initialize render server') |
| 331 | } |
| 332 | |
| 333 | addRequestMeta(req, 'invokePath', invokePath) |
| 334 | addRequestMeta(req, 'invokeQuery', parsedUrl.query) |
| 335 | addRequestMeta(req, 'middlewareInvoke', false) |
| 336 | |
| 337 | for (const key in additionalRequestMeta || {}) { |
| 338 | addRequestMeta( |
| 339 | req, |
| 340 | key as keyof RequestMeta, |
| 341 | additionalRequestMeta![key as keyof RequestMeta] |
| 342 | ) |
| 343 | } |
| 344 | |
| 345 | debug('invokeRender', req.url, req.headers) |
| 346 | |
| 347 | try { |
| 348 | const initResult = |
| 349 | await renderServer?.instance?.initialize(renderServerOpts) |
| 350 | try { |
| 351 | await initResult?.requestHandler(req, res) |
| 352 | } catch (err) { |
| 353 | if (err instanceof NoFallbackError) { |
| 354 | await handleRequest(handleIndex + 1) |
| 355 | return |
no test coverage detected