( res: NextApiResponse, statusOrUrl: string | number, url?: string )
| 57 | * @param url URL of redirect |
| 58 | */ |
| 59 | export 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 | |
| 79 | export function checkIsOnDemandRevalidate( |
| 80 | req: Request | IncomingMessage | BaseNextRequest, |
no test coverage detected