UNPKG

29.2 kBSource Map (JSON)View Raw
1{"version":3,"sources":["../../../next-server/server/api-utils.ts"],"names":["apiResolver","req","res","query","resolverModule","apiContext","propagateError","apiReq","apiRes","statusCode","end","config","bodyParser","api","externalResolver","setLazyProp","getCookieParser","tryGetPreviewData","previewData","undefined","body","parseBody","sizeLimit","status","sendStatusCode","send","data","sendData","json","sendJson","redirect","statusOrUrl","url","setPreviewData","options","Object","assign","clearPreviewData","resolver","wasPiped","process","env","NODE_ENV","once","console","warn","err","ApiError","sendError","message","error","limit","contentType","headers","type","parameters","encoding","charset","buffer","e","toString","parseJson","qs","require","decode","str","length","JSON","parse","parseCookie","header","cookie","parseCookieFn","Array","isArray","join","Error","writeHead","Location","write","getHeader","Stream","setHeader","pipe","isJSONLike","includes","stringifiedBody","stringify","etag","Buffer","isBuffer","byteLength","jsonBody","COOKIE_NAME_PRERENDER_BYPASS","COOKIE_NAME_PRERENDER_DATA","SYMBOL_PREVIEW_DATA","Symbol","SYMBOL_CLEARED_COOKIES","getCookies","cookies","hasBypass","hasData","previewModeId","tokenPreviewData","jsonwebtoken","encryptedPreviewData","verify","previewModeSigningKey","decryptedPreviewData","from","previewModeEncryptionKey","defineProperty","value","enumerable","isNotValidData","payload","sign","algorithm","maxAge","expiresIn","serialize","previous","httpOnly","sameSite","secure","path","expires","Date","constructor","statusMessage","prop","getter","opts","configurable","optsReset","writable","get","set"],"mappings":"yZACA,4DAEA,yDAEA,8BACA,mCACA,2CACA,iDACA,2CACA,kD,mFAWO,cAAeA,CAAAA,WAAf,CACLC,GADK,CAELC,GAFK,CAGLC,KAHK,CAILC,cAJK,CAKLC,UALK,CAMLC,cANK,CAOU,CACf,KAAMC,CAAAA,MAAM,CAAGN,GAAf,CACA,KAAMO,CAAAA,MAAM,CAAGN,GAAf,CAEA,GAAI,8BACF,GAAI,CAACE,cAAL,CAAqB,CACnBF,GAAG,CAACO,UAAJ,CAAiB,GAAjB,CACAP,GAAG,CAACQ,GAAJ,CAAQ,WAAR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ServerResponse } from 'http'\nimport { parse } from 'next/dist/compiled/content-type'\nimport { CookieSerializeOptions } from 'next/dist/compiled/cookie'\nimport getRawBody from 'raw-body'\nimport { PageConfig, PreviewData } from 'next/types'\nimport { Stream } from 'stream'\nimport { isResSent, NextApiRequest, NextApiResponse } from '../lib/utils'\nimport { decryptWithSecret, encryptWithSecret } from './crypto-utils'\nimport { interopDefault } from './load-components'\nimport { sendEtagResponse } from './send-payload'\nimport generateETag from 'etag'\n\nexport type NextApiRequestCookies = { [key: string]: string }\nexport type NextApiRequestQuery = { [key: string]: string | string[] }\n\nexport type __ApiPreviewProps = {\n previewModeId: string\n previewModeEncryptionKey: string\n previewModeSigningKey: string\n}\n\nexport async function apiResolver(\n req: IncomingMessage,\n res: ServerResponse,\n query: any,\n resolverModule: any,\n apiContext: __ApiPreviewProps,\n propagateError: boolean\n): Promise<void> {\n const apiReq = req as NextApiRequest\n const apiRes = res as NextApiResponse\n\n try {\n if (!resolverModule) {\n res.statusCode = 404\n res.end('Not Found')\n return\n }\n const config: PageConfig = resolverModule.config || {}\n const bodyParser = config.api?.bodyParser !== false\n const externalResolver = config.api?.externalResolver || false\n\n // Parsing of cookies\n setLazyProp({ req: apiReq }, 'cookies', getCookieParser(req))\n // Parsing query string\n apiReq.query = query\n // Parsing preview data\n setLazyProp({ req: apiReq }, 'previewData', () =>\n tryGetPreviewData(req, res, apiContext)\n )\n // Checking if preview mode is enabled\n setLazyProp({ req: apiReq }, 'preview', () =>\n apiReq.previewData !== false ? true : undefined\n )\n\n // Parsing of body\n if (bodyParser && !apiReq.body) {\n apiReq.body = await parseBody(\n apiReq,\n config.api && config.api.bodyParser && config.api.bodyParser.sizeLimit\n ? config.api.bodyParser.sizeLimit\n : '1mb'\n )\n }\n\n apiRes.status = (statusCode) => sendStatusCode(apiRes, statusCode)\n apiRes.send = (data) => sendData(apiReq, apiRes, data)\n apiRes.json = (data) => sendJson(apiRes, data)\n apiRes.redirect = (statusOrUrl: number | string, url?: string) =>\n redirect(apiRes, statusOrUrl, url)\n apiRes.setPreviewData = (data, options = {}) =>\n setPreviewData(apiRes, data, Object.assign({}, apiContext, options))\n apiRes.clearPreviewData = () => clearPreviewData(apiRes)\n\n const resolver = interopDefault(resolverModule)\n let wasPiped = false\n\n if (process.env.NODE_ENV !== 'production') {\n // listen for pipe event and don't show resolve warning\n res.once('pipe', () => (wasPiped = true))\n }\n\n // Call API route method\n await resolver(req, res)\n\n if (\n process.env.NODE_ENV !== 'production' &&\n !externalResolver &&\n !isResSent(res) &&\n !wasPiped\n ) {\n console.warn(\n `API resolved without sending a response for ${req.url}, this may result in stalled requests.`\n )\n }\n } catch (err) {\n if (err instanceof ApiError) {\n sendError(apiRes, err.statusCode, err.message)\n } else {\n console.error(err)\n if (propagateError) {\n throw err\n }\n sendError(apiRes, 500, 'Internal Server Error')\n }\n }\n}\n\n/**\n * Parse incoming message like `json` or `urlencoded`\n * @param req request object\n */\nexport async function parseBody(\n req: NextApiRequest,\n limit: string | number\n): Promise<any> {\n let contentType\n try {\n contentType = parse(req.headers['content-type'] || 'text/plain')\n } catch {\n contentType = parse('text/plain')\n }\n const { type, parameters } = contentType\n const encoding = parameters.charset || 'utf-8'\n\n let buffer\n\n try {\n buffer = await getRawBody(req, { encoding, limit })\n } catch (e) {\n if (e.type === 'entity.too.large') {\n throw new ApiError(413, `Body exceeded ${limit} limit`)\n } else {\n throw new ApiError(400, 'Invalid body')\n }\n }\n\n const body = buffer.toString()\n\n if (type === 'application/json' || type === 'application/ld+json') {\n return parseJson(body)\n } else if (type === 'application/x-www-form-urlencoded') {\n const qs = require('querystring')\n return qs.decode(body)\n } else {\n return body\n }\n}\n\n/**\n * Parse `JSON` and handles invalid `JSON` strings\n * @param str `JSON` string\n */\nfunction parseJson(str: string): object {\n if (str.length === 0) {\n // special-case empty json body, as it's a common client-side mistake\n return {}\n }\n\n try {\n return JSON.parse(str)\n } catch (e) {\n throw new ApiError(400, 'Invalid JSON')\n }\n}\n\n/**\n * Parse cookies from `req` header\n * @param req request object\n */\nexport function getCookieParser(\n req: IncomingMessage\n): () => NextApiRequestCookies {\n return function parseCookie(): NextApiRequestCookies {\n const header: undefined | string | string[] = req.headers.cookie\n\n if (!header) {\n return {}\n }\n\n const { parse: parseCookieFn } = require('next/dist/compiled/cookie')\n return parseCookieFn(Array.isArray(header) ? header.join(';') : header)\n }\n}\n\n/**\n *\n * @param res response object\n * @param statusCode `HTTP` status code of response\n */\nexport function sendStatusCode(\n res: NextApiResponse,\n statusCode: number\n): NextApiResponse<any> {\n res.statusCode = statusCode\n return res\n}\n\n/**\n *\n * @param res response object\n * @param [statusOrUrl] `HTTP` status code of redirect\n * @param url URL of redirect\n */\nexport function redirect(\n res: NextApiResponse,\n statusOrUrl: string | number,\n url?: string\n): NextApiResponse<any> {\n if (typeof statusOrUrl === 'string') {\n url = statusOrUrl\n statusOrUrl = 307\n }\n if (typeof statusOrUrl !== 'number' || typeof url !== 'string') {\n throw new Error(\n `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').`\n )\n }\n res.writeHead(statusOrUrl, { Location: url })\n res.write('')\n res.end()\n return res\n}\n\n/**\n * Send `any` body to response\n * @param req request object\n * @param res response object\n * @param body of response\n */\nexport function sendData(\n req: NextApiRequest,\n res: NextApiResponse,\n body: any\n): void {\n if (body === null || body === undefined) {\n res.end()\n return\n }\n\n const contentType = res.getHeader('Content-Type')\n\n if (body instanceof Stream) {\n if (!contentType) {\n res.setHeader('Content-Type', 'application/octet-stream')\n }\n body.pipe(res)\n return\n }\n\n const isJSONLike = ['object', 'number', 'boolean'].includes(typeof body)\n const stringifiedBody = isJSONLike ? JSON.stringify(body) : body\n const etag = generateETag(stringifiedBody)\n if (sendEtagResponse(req, res, etag)) {\n return\n }\n\n if (Buffer.isBuffer(body)) {\n if (!contentType) {\n res.setHeader('Content-Type', 'application/octet-stream')\n }\n res.setHeader('Content-Length', body.length)\n res.end(body)\n return\n }\n\n if (isJSONLike) {\n res.setHeader('Content-Type', 'application/json; charset=utf-8')\n }\n\n res.setHeader('Content-Length', Buffer.byteLength(stringifiedBody))\n res.end(stringifiedBody)\n}\n\n/**\n * Send `JSON` object\n * @param res response object\n * @param jsonBody of data\n */\nexport function sendJson(res: NextApiResponse, jsonBody: any): void {\n // Set header to application/json\n res.setHeader('Content-Type', 'application/json; charset=utf-8')\n\n // Use send to handle request\n res.send(jsonBody)\n}\n\nconst COOKIE_NAME_PRERENDER_BYPASS = `__prerender_bypass`\nconst COOKIE_NAME_PRERENDER_DATA = `__next_preview_data`\n\nexport const SYMBOL_PREVIEW_DATA = Symbol(COOKIE_NAME_PRERENDER_DATA)\nconst SYMBOL_CLEARED_COOKIES = Symbol(COOKIE_NAME_PRERENDER_BYPASS)\n\nexport function tryGetPreviewData(\n req: IncomingMessage,\n res: ServerResponse,\n options: __ApiPreviewProps\n): PreviewData {\n // Read cached preview data if present\n if (SYMBOL_PREVIEW_DATA in req) {\n return (req as any)[SYMBOL_PREVIEW_DATA] as any\n }\n\n const getCookies = getCookieParser(req)\n let cookies: NextApiRequestCookies\n try {\n cookies = getCookies()\n } catch {\n // TODO: warn\n return false\n }\n\n const hasBypass = COOKIE_NAME_PRERENDER_BYPASS in cookies\n const hasData = COOKIE_NAME_PRERENDER_DATA in cookies\n\n // Case: neither cookie is set.\n if (!(hasBypass || hasData)) {\n return false\n }\n\n // Case: one cookie is set, but not the other.\n if (hasBypass !== hasData) {\n clearPreviewData(res as NextApiResponse)\n return false\n }\n\n // Case: preview session is for an old build.\n if (cookies[COOKIE_NAME_PRERENDER_BYPASS] !== options.previewModeId) {\n clearPreviewData(res as NextApiResponse)\n return false\n }\n\n const tokenPreviewData = cookies[COOKIE_NAME_PRERENDER_DATA]\n\n const jsonwebtoken = require('next/dist/compiled/jsonwebtoken') as typeof import('jsonwebtoken')\n let encryptedPreviewData: {\n data: string\n }\n try {\n encryptedPreviewData = jsonwebtoken.verify(\n tokenPreviewData,\n options.previewModeSigningKey\n ) as typeof encryptedPreviewData\n } catch {\n // TODO: warn\n clearPreviewData(res as NextApiResponse)\n return false\n }\n\n const decryptedPreviewData = decryptWithSecret(\n Buffer.from(options.previewModeEncryptionKey),\n encryptedPreviewData.data\n )\n\n try {\n // TODO: strict runtime type checking\n const data = JSON.parse(decryptedPreviewData)\n // Cache lookup\n Object.defineProperty(req, SYMBOL_PREVIEW_DATA, {\n value: data,\n enumerable: false,\n })\n return data\n } catch {\n return false\n }\n}\n\nfunction isNotValidData(str: string): boolean {\n return typeof str !== 'string' || str.length < 16\n}\n\nfunction setPreviewData<T>(\n res: NextApiResponse<T>,\n data: object | string, // TODO: strict runtime type checking\n options: {\n maxAge?: number\n } & __ApiPreviewProps\n): NextApiResponse<T> {\n if (isNotValidData(options.previewModeId)) {\n throw new Error('invariant: invalid previewModeId')\n }\n if (isNotValidData(options.previewModeEncryptionKey)) {\n throw new Error('invariant: invalid previewModeEncryptionKey')\n }\n if (isNotValidData(options.previewModeSigningKey)) {\n throw new Error('invariant: invalid previewModeSigningKey')\n }\n\n const jsonwebtoken = require('next/dist/compiled/jsonwebtoken') as typeof import('jsonwebtoken')\n\n const payload = jsonwebtoken.sign(\n {\n data: encryptWithSecret(\n Buffer.from(options.previewModeEncryptionKey),\n JSON.stringify(data)\n ),\n },\n options.previewModeSigningKey,\n {\n algorithm: 'HS256',\n ...(options.maxAge !== undefined\n ? { expiresIn: options.maxAge }\n : undefined),\n }\n )\n\n // limit preview mode cookie to 2KB since we shouldn't store too much\n // data here and browsers drop cookies over 4KB\n if (payload.length > 2048) {\n throw new Error(\n `Preview data is limited to 2KB currently, reduce how much data you are storing as preview data to continue`\n )\n }\n\n const {\n serialize,\n } = require('next/dist/compiled/cookie') as typeof import('cookie')\n const previous = res.getHeader('Set-Cookie')\n res.setHeader(`Set-Cookie`, [\n ...(typeof previous === 'string'\n ? [previous]\n : Array.isArray(previous)\n ? previous\n : []),\n serialize(COOKIE_NAME_PRERENDER_BYPASS, options.previewModeId, {\n httpOnly: true,\n sameSite: process.env.NODE_ENV !== 'development' ? 'none' : 'lax',\n secure: process.env.NODE_ENV !== 'development',\n path: '/',\n ...(options.maxAge !== undefined\n ? ({ maxAge: options.maxAge } as CookieSerializeOptions)\n : undefined),\n }),\n serialize(COOKIE_NAME_PRERENDER_DATA, payload, {\n httpOnly: true,\n sameSite: process.env.NODE_ENV !== 'development' ? 'none' : 'lax',\n secure: process.env.NODE_ENV !== 'development',\n path: '/',\n ...(options.maxAge !== undefined\n ? ({ maxAge: options.maxAge } as CookieSerializeOptions)\n : undefined),\n }),\n ])\n return res\n}\n\nfunction clearPreviewData<T>(res: NextApiResponse<T>): NextApiResponse<T> {\n if (SYMBOL_CLEARED_COOKIES in res) {\n return res\n }\n\n const {\n serialize,\n } = require('next/dist/compiled/cookie') as typeof import('cookie')\n const previous = res.getHeader('Set-Cookie')\n res.setHeader(`Set-Cookie`, [\n ...(typeof previous === 'string'\n ? [previous]\n : Array.isArray(previous)\n ? previous\n : []),\n serialize(COOKIE_NAME_PRERENDER_BYPASS, '', {\n // To delete a cookie, set `expires` to a date in the past:\n // https://tools.ietf.org/html/rfc6265#section-4.1.1\n // `Max-Age: 0` is not valid, thus ignored, and the cookie is persisted.\n expires: new Date(0),\n httpOnly: true,\n sameSite: process.env.NODE_ENV !== 'development' ? 'none' : 'lax',\n secure: process.env.NODE_ENV !== 'development',\n path: '/',\n }),\n serialize(COOKIE_NAME_PRERENDER_DATA, '', {\n // To delete a cookie, set `expires` to a date in the past:\n // https://tools.ietf.org/html/rfc6265#section-4.1.1\n // `Max-Age: 0` is not valid, thus ignored, and the cookie is persisted.\n expires: new Date(0),\n httpOnly: true,\n sameSite: process.env.NODE_ENV !== 'development' ? 'none' : 'lax',\n secure: process.env.NODE_ENV !== 'development',\n path: '/',\n }),\n ])\n\n Object.defineProperty(res, SYMBOL_CLEARED_COOKIES, {\n value: true,\n enumerable: false,\n })\n return res\n}\n\n/**\n * Custom error class\n */\nexport class ApiError extends Error {\n readonly statusCode: number\n\n constructor(statusCode: number, message: string) {\n super(message)\n this.statusCode = statusCode\n }\n}\n\n/**\n * Sends error in `response`\n * @param res response object\n * @param statusCode of response\n * @param message of response\n */\nexport function sendError(\n res: NextApiResponse,\n statusCode: number,\n message: string\n): void {\n res.statusCode = statusCode\n res.statusMessage = message\n res.end(message)\n}\n\ninterface LazyProps {\n req: NextApiRequest\n}\n\n/**\n * Execute getter function only if its needed\n * @param LazyProps `req` and `params` for lazyProp\n * @param prop name of property\n * @param getter function to get data\n */\nexport function setLazyProp<T>(\n { req }: LazyProps,\n prop: string,\n getter: () => T\n): void {\n const opts = { configurable: true, enumerable: true }\n const optsReset = { ...opts, writable: true }\n\n Object.defineProperty(req, prop, {\n ...opts,\n get: () => {\n const value = getter()\n // we set the property on the object to avoid recalculating it\n Object.defineProperty(req, prop, { ...optsReset, value })\n return value\n },\n set: (value) => {\n Object.defineProperty(req, prop, { ...optsReset, value })\n },\n })\n}\n"]}
\No newline at end of file