MCPcopy
hub / github.com/vercel/next.js / requestHandlerImpl

Function requestHandlerImpl

packages/next/src/server/lib/router-server.ts:226–722  ·  view source on GitHub ↗
(req, res)

Source from the content-addressed store, hash-verified

224 require('./render-server') as typeof import('./render-server')
225
226 const requestHandlerImpl: WorkerRequestHandler = async (req, res) => {
227 addRequestMeta(req, 'relativeProjectDir', relativeProjectDir)
228
229 // internal headers should not be honored by the request handler
230 if (!process.env.NEXT_PRIVATE_TEST_HEADERS) {
231 filterInternalHeaders(req.headers)
232 }
233
234 if (
235 !opts.minimalMode &&
236 config.i18n &&
237 config.i18n.localeDetection !== false
238 ) {
239 const urlParts = (req.url || '').split('?', 1)
240 let urlNoQuery = urlParts[0] || ''
241
242 if (config.basePath) {
243 urlNoQuery = removePathPrefix(urlNoQuery, config.basePath)
244 }
245
246 const pathnameInfo = getNextPathnameInfo(urlNoQuery, {
247 nextConfig: config,
248 })
249
250 const domainLocale = detectDomainLocale(
251 config.i18n.domains,
252 getHostname({ hostname: urlNoQuery }, req.headers)
253 )
254
255 const defaultLocale =
256 domainLocale?.defaultLocale || config.i18n.defaultLocale
257
258 const { getLocaleRedirect } =
259 require('../../shared/lib/i18n/get-locale-redirect') as typeof import('../../shared/lib/i18n/get-locale-redirect')
260
261 const parsedUrl = parseUrlUtil((req.url || '')?.replace(/^\/+/, '/'))
262
263 const redirect = getLocaleRedirect({
264 defaultLocale,
265 domainLocale,
266 headers: req.headers,
267 nextConfig: config,
268 pathLocale: pathnameInfo.locale,
269 urlParsed: {
270 ...parsedUrl,
271 pathname: pathnameInfo.locale
272 ? `/${pathnameInfo.locale}${urlNoQuery}`
273 : urlNoQuery,
274 },
275 })
276
277 if (redirect) {
278 res.setHeader('Location', redirect)
279 res.statusCode = RedirectStatusCode.TemporaryRedirect
280 res.end(redirect)
281 return
282 }
283 }

Callers

nothing calls this directly

Calls 15

addRequestMetaFunction · 0.90
filterInternalHeadersFunction · 0.90
removePathPrefixFunction · 0.90
getNextPathnameInfoFunction · 0.90
detectDomainLocaleFunction · 0.90
getHostnameFunction · 0.90
getLocaleRedirectFunction · 0.85
invokeRenderFunction · 0.85
splitMethod · 0.80
handleRequestFunction · 0.70
replaceMethod · 0.65
endMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…