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

Function redirect

packages/next/src/server/api-utils/index.ts:59–77  ·  view source on GitHub ↗
(
  res: NextApiResponse,
  statusOrUrl: string | number,
  url?: string
)

Source from the content-addressed store, hash-verified

57 * @param url URL of redirect
58 */
59export function redirect(
60 res: NextApiResponse,
61 statusOrUrl: string | number,
62 url?: string
63): NextApiResponse<any> {
64 if (typeof statusOrUrl === 'string') {
65 url = statusOrUrl
66 statusOrUrl = 307
67 }
68 if (typeof statusOrUrl !== 'number' || typeof url !== 'string') {
69 throw new Error(
70 `Invalid redirect arguments. Please use a single argument URL, e.g. res.redirect('/destination') or use a status code and URL, e.g. res.redirect(307, '/destination').`
71 )
72 }
73 res.writeHead(statusOrUrl, { Location: url })
74 res.write(url)
75 res.end()
76 return res
77}
78
79export function checkIsOnDemandRevalidate(
80 req: Request | IncomingMessage | BaseNextRequest,

Callers 1

apiResolverFunction · 0.90

Calls 3

writeHeadMethod · 0.80
endMethod · 0.65
writeMethod · 0.45

Tested by

no test coverage detected