Initial boiler plate project
This commit is contained in:
15
node_modules/next/dist/esm/server/api-utils/get-cookie-parser.js
generated
vendored
Normal file
15
node_modules/next/dist/esm/server/api-utils/get-cookie-parser.js
generated
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Parse cookies from the `headers` of request
|
||||
* @param req request object
|
||||
*/ export function getCookieParser(headers) {
|
||||
return function parseCookie() {
|
||||
const { cookie } = headers;
|
||||
if (!cookie) {
|
||||
return {};
|
||||
}
|
||||
const { parse: parseCookieFn } = require("next/dist/compiled/cookie");
|
||||
return parseCookieFn(Array.isArray(cookie) ? cookie.join("; ") : cookie);
|
||||
};
|
||||
}
|
||||
|
||||
//# sourceMappingURL=get-cookie-parser.js.map
|
||||
1
node_modules/next/dist/esm/server/api-utils/get-cookie-parser.js.map
generated
vendored
Normal file
1
node_modules/next/dist/esm/server/api-utils/get-cookie-parser.js.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../src/server/api-utils/get-cookie-parser.ts"],"names":["getCookieParser","headers","parseCookie","cookie","parse","parseCookieFn","require","Array","isArray","join"],"mappings":"AAEA;;;CAGC,GAED,OAAO,SAASA,gBAAgBC,OAE/B;IACC,OAAO,SAASC;QACd,MAAM,EAAEC,MAAM,EAAE,GAAGF;QAEnB,IAAI,CAACE,QAAQ;YACX,OAAO,CAAC;QACV;QAEA,MAAM,EAAEC,OAAOC,aAAa,EAAE,GAAGC,QAAQ;QACzC,OAAOD,cAAcE,MAAMC,OAAO,CAACL,UAAUA,OAAOM,IAAI,CAAC,QAAQN;IACnE;AACF"}
|
||||
153
node_modules/next/dist/esm/server/api-utils/index.js
generated
vendored
Normal file
153
node_modules/next/dist/esm/server/api-utils/index.js
generated
vendored
Normal file
@ -0,0 +1,153 @@
|
||||
import { HeadersAdapter } from "../web/spec-extension/adapters/headers";
|
||||
import { PRERENDER_REVALIDATE_HEADER, PRERENDER_REVALIDATE_ONLY_GENERATED_HEADER } from "../../lib/constants";
|
||||
import { getTracer } from "../lib/trace/tracer";
|
||||
import { NodeSpan } from "../lib/trace/constants";
|
||||
export function wrapApiHandler(page, handler) {
|
||||
return (...args)=>{
|
||||
var _getTracer_getRootSpanAttributes;
|
||||
(_getTracer_getRootSpanAttributes = getTracer().getRootSpanAttributes()) == null ? void 0 : _getTracer_getRootSpanAttributes.set("next.route", page);
|
||||
// Call API route method
|
||||
return getTracer().trace(NodeSpan.runHandler, {
|
||||
spanName: `executing api route (pages) ${page}`
|
||||
}, ()=>handler(...args));
|
||||
};
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param res response object
|
||||
* @param statusCode `HTTP` status code of response
|
||||
*/ export function sendStatusCode(res, statusCode) {
|
||||
res.statusCode = statusCode;
|
||||
return res;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param res response object
|
||||
* @param [statusOrUrl] `HTTP` status code of redirect
|
||||
* @param url URL of redirect
|
||||
*/ export function redirect(res, statusOrUrl, url) {
|
||||
if (typeof statusOrUrl === "string") {
|
||||
url = statusOrUrl;
|
||||
statusOrUrl = 307;
|
||||
}
|
||||
if (typeof statusOrUrl !== "number" || typeof url !== "string") {
|
||||
throw new Error(`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').`);
|
||||
}
|
||||
res.writeHead(statusOrUrl, {
|
||||
Location: url
|
||||
});
|
||||
res.write(url);
|
||||
res.end();
|
||||
return res;
|
||||
}
|
||||
export function checkIsOnDemandRevalidate(req, previewProps) {
|
||||
const headers = HeadersAdapter.from(req.headers);
|
||||
const previewModeId = headers.get(PRERENDER_REVALIDATE_HEADER);
|
||||
const isOnDemandRevalidate = previewModeId === previewProps.previewModeId;
|
||||
const revalidateOnlyGenerated = headers.has(PRERENDER_REVALIDATE_ONLY_GENERATED_HEADER);
|
||||
return {
|
||||
isOnDemandRevalidate,
|
||||
revalidateOnlyGenerated
|
||||
};
|
||||
}
|
||||
export const COOKIE_NAME_PRERENDER_BYPASS = `__prerender_bypass`;
|
||||
export const COOKIE_NAME_PRERENDER_DATA = `__next_preview_data`;
|
||||
export const RESPONSE_LIMIT_DEFAULT = 4 * 1024 * 1024;
|
||||
export const SYMBOL_PREVIEW_DATA = Symbol(COOKIE_NAME_PRERENDER_DATA);
|
||||
export const SYMBOL_CLEARED_COOKIES = Symbol(COOKIE_NAME_PRERENDER_BYPASS);
|
||||
export function clearPreviewData(res, options = {}) {
|
||||
if (SYMBOL_CLEARED_COOKIES in res) {
|
||||
return res;
|
||||
}
|
||||
const { serialize } = require("next/dist/compiled/cookie");
|
||||
const previous = res.getHeader("Set-Cookie");
|
||||
res.setHeader(`Set-Cookie`, [
|
||||
...typeof previous === "string" ? [
|
||||
previous
|
||||
] : Array.isArray(previous) ? previous : [],
|
||||
serialize(COOKIE_NAME_PRERENDER_BYPASS, "", {
|
||||
// To delete a cookie, set `expires` to a date in the past:
|
||||
// https://tools.ietf.org/html/rfc6265#section-4.1.1
|
||||
// `Max-Age: 0` is not valid, thus ignored, and the cookie is persisted.
|
||||
expires: new Date(0),
|
||||
httpOnly: true,
|
||||
sameSite: process.env.NODE_ENV !== "development" ? "none" : "lax",
|
||||
secure: process.env.NODE_ENV !== "development",
|
||||
path: "/",
|
||||
...options.path !== undefined ? {
|
||||
path: options.path
|
||||
} : undefined
|
||||
}),
|
||||
serialize(COOKIE_NAME_PRERENDER_DATA, "", {
|
||||
// To delete a cookie, set `expires` to a date in the past:
|
||||
// https://tools.ietf.org/html/rfc6265#section-4.1.1
|
||||
// `Max-Age: 0` is not valid, thus ignored, and the cookie is persisted.
|
||||
expires: new Date(0),
|
||||
httpOnly: true,
|
||||
sameSite: process.env.NODE_ENV !== "development" ? "none" : "lax",
|
||||
secure: process.env.NODE_ENV !== "development",
|
||||
path: "/",
|
||||
...options.path !== undefined ? {
|
||||
path: options.path
|
||||
} : undefined
|
||||
})
|
||||
]);
|
||||
Object.defineProperty(res, SYMBOL_CLEARED_COOKIES, {
|
||||
value: true,
|
||||
enumerable: false
|
||||
});
|
||||
return res;
|
||||
}
|
||||
/**
|
||||
* Custom error class
|
||||
*/ export class ApiError extends Error {
|
||||
constructor(statusCode, message){
|
||||
super(message);
|
||||
this.statusCode = statusCode;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Sends error in `response`
|
||||
* @param res response object
|
||||
* @param statusCode of response
|
||||
* @param message of response
|
||||
*/ export function sendError(res, statusCode, message) {
|
||||
res.statusCode = statusCode;
|
||||
res.statusMessage = message;
|
||||
res.end(message);
|
||||
}
|
||||
/**
|
||||
* Execute getter function only if its needed
|
||||
* @param LazyProps `req` and `params` for lazyProp
|
||||
* @param prop name of property
|
||||
* @param getter function to get data
|
||||
*/ export function setLazyProp({ req }, prop, getter) {
|
||||
const opts = {
|
||||
configurable: true,
|
||||
enumerable: true
|
||||
};
|
||||
const optsReset = {
|
||||
...opts,
|
||||
writable: true
|
||||
};
|
||||
Object.defineProperty(req, prop, {
|
||||
...opts,
|
||||
get: ()=>{
|
||||
const value = getter();
|
||||
// we set the property on the object to avoid recalculating it
|
||||
Object.defineProperty(req, prop, {
|
||||
...optsReset,
|
||||
value
|
||||
});
|
||||
return value;
|
||||
},
|
||||
set: (value)=>{
|
||||
Object.defineProperty(req, prop, {
|
||||
...optsReset,
|
||||
value
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
node_modules/next/dist/esm/server/api-utils/index.js.map
generated
vendored
Normal file
1
node_modules/next/dist/esm/server/api-utils/index.js.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../src/server/api-utils/index.ts"],"names":["HeadersAdapter","PRERENDER_REVALIDATE_HEADER","PRERENDER_REVALIDATE_ONLY_GENERATED_HEADER","getTracer","NodeSpan","wrapApiHandler","page","handler","args","getRootSpanAttributes","set","trace","runHandler","spanName","sendStatusCode","res","statusCode","redirect","statusOrUrl","url","Error","writeHead","Location","write","end","checkIsOnDemandRevalidate","req","previewProps","headers","from","previewModeId","get","isOnDemandRevalidate","revalidateOnlyGenerated","has","COOKIE_NAME_PRERENDER_BYPASS","COOKIE_NAME_PRERENDER_DATA","RESPONSE_LIMIT_DEFAULT","SYMBOL_PREVIEW_DATA","Symbol","SYMBOL_CLEARED_COOKIES","clearPreviewData","options","serialize","require","previous","getHeader","setHeader","Array","isArray","expires","Date","httpOnly","sameSite","process","env","NODE_ENV","secure","path","undefined","Object","defineProperty","value","enumerable","ApiError","constructor","message","sendError","statusMessage","setLazyProp","prop","getter","opts","configurable","optsReset","writable"],"mappings":"AAKA,SAASA,cAAc,QAAQ,yCAAwC;AACvE,SACEC,2BAA2B,EAC3BC,0CAA0C,QACrC,sBAAqB;AAC5B,SAASC,SAAS,QAAQ,sBAAqB;AAC/C,SAASC,QAAQ,QAAQ,yBAAwB;AAWjD,OAAO,SAASC,eACdC,IAAY,EACZC,OAAU;IAEV,OAAQ,CAAC,GAAGC;YACVL;SAAAA,mCAAAA,YAAYM,qBAAqB,uBAAjCN,iCAAqCO,GAAG,CAAC,cAAcJ;QACvD,wBAAwB;QACxB,OAAOH,YAAYQ,KAAK,CACtBP,SAASQ,UAAU,EACnB;YACEC,UAAU,CAAC,4BAA4B,EAAEP,KAAK,CAAC;QACjD,GACA,IAAMC,WAAWC;IAErB;AACF;AAEA;;;;CAIC,GACD,OAAO,SAASM,eACdC,GAAoB,EACpBC,UAAkB;IAElBD,IAAIC,UAAU,GAAGA;IACjB,OAAOD;AACT;AAEA;;;;;CAKC,GACD,OAAO,SAASE,SACdF,GAAoB,EACpBG,WAA4B,EAC5BC,GAAY;IAEZ,IAAI,OAAOD,gBAAgB,UAAU;QACnCC,MAAMD;QACNA,cAAc;IAChB;IACA,IAAI,OAAOA,gBAAgB,YAAY,OAAOC,QAAQ,UAAU;QAC9D,MAAM,IAAIC,MACR,CAAC,qKAAqK,CAAC;IAE3K;IACAL,IAAIM,SAAS,CAACH,aAAa;QAAEI,UAAUH;IAAI;IAC3CJ,IAAIQ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AAGI,SAAS;gBAAEZ;YAAM;QACzD;IACF;AACF"}
|
||||
315
node_modules/next/dist/esm/server/api-utils/node/api-resolver.js
generated
vendored
Normal file
315
node_modules/next/dist/esm/server/api-utils/node/api-resolver.js
generated
vendored
Normal file
@ -0,0 +1,315 @@
|
||||
import bytes from "next/dist/compiled/bytes";
|
||||
import { generateETag } from "../../lib/etag";
|
||||
import { sendEtagResponse } from "../../send-payload";
|
||||
import { Stream } from "stream";
|
||||
import isError from "../../../lib/is-error";
|
||||
import { isResSent } from "../../../shared/lib/utils";
|
||||
import { interopDefault } from "../../../lib/interop-default";
|
||||
import { setLazyProp, sendStatusCode, redirect, clearPreviewData, sendError, ApiError, COOKIE_NAME_PRERENDER_BYPASS, COOKIE_NAME_PRERENDER_DATA, RESPONSE_LIMIT_DEFAULT } from "./../index";
|
||||
import { getCookieParser } from "./../get-cookie-parser";
|
||||
import { PRERENDER_REVALIDATE_HEADER, PRERENDER_REVALIDATE_ONLY_GENERATED_HEADER } from "../../../lib/constants";
|
||||
import { tryGetPreviewData } from "./try-get-preview-data";
|
||||
import { parseBody } from "./parse-body";
|
||||
function getMaxContentLength(responseLimit) {
|
||||
if (responseLimit && typeof responseLimit !== "boolean") {
|
||||
return bytes.parse(responseLimit);
|
||||
}
|
||||
return RESPONSE_LIMIT_DEFAULT;
|
||||
}
|
||||
/**
|
||||
* Send `any` body to response
|
||||
* @param req request object
|
||||
* @param res response object
|
||||
* @param body of response
|
||||
*/ function sendData(req, res, body) {
|
||||
if (body === null || body === undefined) {
|
||||
res.end();
|
||||
return;
|
||||
}
|
||||
// strip irrelevant headers/body
|
||||
if (res.statusCode === 204 || res.statusCode === 304) {
|
||||
res.removeHeader("Content-Type");
|
||||
res.removeHeader("Content-Length");
|
||||
res.removeHeader("Transfer-Encoding");
|
||||
if (process.env.NODE_ENV === "development" && body) {
|
||||
console.warn(`A body was attempted to be set with a 204 statusCode for ${req.url}, this is invalid and the body was ignored.\n` + `See more info here https://nextjs.org/docs/messages/invalid-api-status-body`);
|
||||
}
|
||||
res.end();
|
||||
return;
|
||||
}
|
||||
const contentType = res.getHeader("Content-Type");
|
||||
if (body instanceof Stream) {
|
||||
if (!contentType) {
|
||||
res.setHeader("Content-Type", "application/octet-stream");
|
||||
}
|
||||
body.pipe(res);
|
||||
return;
|
||||
}
|
||||
const isJSONLike = [
|
||||
"object",
|
||||
"number",
|
||||
"boolean"
|
||||
].includes(typeof body);
|
||||
const stringifiedBody = isJSONLike ? JSON.stringify(body) : body;
|
||||
const etag = generateETag(stringifiedBody);
|
||||
if (sendEtagResponse(req, res, etag)) {
|
||||
return;
|
||||
}
|
||||
if (Buffer.isBuffer(body)) {
|
||||
if (!contentType) {
|
||||
res.setHeader("Content-Type", "application/octet-stream");
|
||||
}
|
||||
res.setHeader("Content-Length", body.length);
|
||||
res.end(body);
|
||||
return;
|
||||
}
|
||||
if (isJSONLike) {
|
||||
res.setHeader("Content-Type", "application/json; charset=utf-8");
|
||||
}
|
||||
res.setHeader("Content-Length", Buffer.byteLength(stringifiedBody));
|
||||
res.end(stringifiedBody);
|
||||
}
|
||||
/**
|
||||
* Send `JSON` object
|
||||
* @param res response object
|
||||
* @param jsonBody of data
|
||||
*/ function sendJson(res, jsonBody) {
|
||||
// Set header to application/json
|
||||
res.setHeader("Content-Type", "application/json; charset=utf-8");
|
||||
// Use send to handle request
|
||||
res.send(JSON.stringify(jsonBody));
|
||||
}
|
||||
function isValidData(str) {
|
||||
return typeof str === "string" && str.length >= 16;
|
||||
}
|
||||
function setDraftMode(res, options) {
|
||||
if (!isValidData(options.previewModeId)) {
|
||||
throw new Error("invariant: invalid previewModeId");
|
||||
}
|
||||
const expires = options.enable ? undefined : new Date(0);
|
||||
// To delete a cookie, set `expires` to a date in the past:
|
||||
// https://tools.ietf.org/html/rfc6265#section-4.1.1
|
||||
// `Max-Age: 0` is not valid, thus ignored, and the cookie is persisted.
|
||||
const { serialize } = require("next/dist/compiled/cookie");
|
||||
const previous = res.getHeader("Set-Cookie");
|
||||
res.setHeader(`Set-Cookie`, [
|
||||
...typeof previous === "string" ? [
|
||||
previous
|
||||
] : Array.isArray(previous) ? previous : [],
|
||||
serialize(COOKIE_NAME_PRERENDER_BYPASS, options.previewModeId, {
|
||||
httpOnly: true,
|
||||
sameSite: process.env.NODE_ENV !== "development" ? "none" : "lax",
|
||||
secure: process.env.NODE_ENV !== "development",
|
||||
path: "/",
|
||||
expires
|
||||
})
|
||||
]);
|
||||
return res;
|
||||
}
|
||||
function setPreviewData(res, data, options) {
|
||||
if (!isValidData(options.previewModeId)) {
|
||||
throw new Error("invariant: invalid previewModeId");
|
||||
}
|
||||
if (!isValidData(options.previewModeEncryptionKey)) {
|
||||
throw new Error("invariant: invalid previewModeEncryptionKey");
|
||||
}
|
||||
if (!isValidData(options.previewModeSigningKey)) {
|
||||
throw new Error("invariant: invalid previewModeSigningKey");
|
||||
}
|
||||
const jsonwebtoken = require("next/dist/compiled/jsonwebtoken");
|
||||
const { encryptWithSecret } = require("../../crypto-utils");
|
||||
const payload = jsonwebtoken.sign({
|
||||
data: encryptWithSecret(Buffer.from(options.previewModeEncryptionKey), JSON.stringify(data))
|
||||
}, options.previewModeSigningKey, {
|
||||
algorithm: "HS256",
|
||||
...options.maxAge !== undefined ? {
|
||||
expiresIn: options.maxAge
|
||||
} : undefined
|
||||
});
|
||||
// limit preview mode cookie to 2KB since we shouldn't store too much
|
||||
// data here and browsers drop cookies over 4KB
|
||||
if (payload.length > 2048) {
|
||||
throw new Error(`Preview data is limited to 2KB currently, reduce how much data you are storing as preview data to continue`);
|
||||
}
|
||||
const { serialize } = require("next/dist/compiled/cookie");
|
||||
const previous = res.getHeader("Set-Cookie");
|
||||
res.setHeader(`Set-Cookie`, [
|
||||
...typeof previous === "string" ? [
|
||||
previous
|
||||
] : Array.isArray(previous) ? previous : [],
|
||||
serialize(COOKIE_NAME_PRERENDER_BYPASS, options.previewModeId, {
|
||||
httpOnly: true,
|
||||
sameSite: process.env.NODE_ENV !== "development" ? "none" : "lax",
|
||||
secure: process.env.NODE_ENV !== "development",
|
||||
path: "/",
|
||||
...options.maxAge !== undefined ? {
|
||||
maxAge: options.maxAge
|
||||
} : undefined,
|
||||
...options.path !== undefined ? {
|
||||
path: options.path
|
||||
} : undefined
|
||||
}),
|
||||
serialize(COOKIE_NAME_PRERENDER_DATA, payload, {
|
||||
httpOnly: true,
|
||||
sameSite: process.env.NODE_ENV !== "development" ? "none" : "lax",
|
||||
secure: process.env.NODE_ENV !== "development",
|
||||
path: "/",
|
||||
...options.maxAge !== undefined ? {
|
||||
maxAge: options.maxAge
|
||||
} : undefined,
|
||||
...options.path !== undefined ? {
|
||||
path: options.path
|
||||
} : undefined
|
||||
})
|
||||
]);
|
||||
return res;
|
||||
}
|
||||
async function revalidate(urlPath, opts, req, context) {
|
||||
if (typeof urlPath !== "string" || !urlPath.startsWith("/")) {
|
||||
throw new Error(`Invalid urlPath provided to revalidate(), must be a path e.g. /blog/post-1, received ${urlPath}`);
|
||||
}
|
||||
const revalidateHeaders = {
|
||||
[PRERENDER_REVALIDATE_HEADER]: context.previewModeId,
|
||||
...opts.unstable_onlyGenerated ? {
|
||||
[PRERENDER_REVALIDATE_ONLY_GENERATED_HEADER]: "1"
|
||||
} : {}
|
||||
};
|
||||
const allowedRevalidateHeaderKeys = [
|
||||
...context.allowedRevalidateHeaderKeys || [],
|
||||
...context.trustHostHeader ? [
|
||||
"cookie",
|
||||
"x-vercel-protection-bypass"
|
||||
] : []
|
||||
];
|
||||
for (const key of Object.keys(req.headers)){
|
||||
if (allowedRevalidateHeaderKeys.includes(key)) {
|
||||
revalidateHeaders[key] = req.headers[key];
|
||||
}
|
||||
}
|
||||
try {
|
||||
if (context.trustHostHeader) {
|
||||
const res = await fetch(`https://${req.headers.host}${urlPath}`, {
|
||||
method: "HEAD",
|
||||
headers: revalidateHeaders
|
||||
});
|
||||
// we use the cache header to determine successful revalidate as
|
||||
// a non-200 status code can be returned from a successful revalidate
|
||||
// e.g. notFound: true returns 404 status code but is successful
|
||||
const cacheHeader = res.headers.get("x-vercel-cache") || res.headers.get("x-nextjs-cache");
|
||||
if ((cacheHeader == null ? void 0 : cacheHeader.toUpperCase()) !== "REVALIDATED" && !(res.status === 404 && opts.unstable_onlyGenerated)) {
|
||||
throw new Error(`Invalid response ${res.status}`);
|
||||
}
|
||||
} else if (context.revalidate) {
|
||||
await context.revalidate({
|
||||
urlPath,
|
||||
revalidateHeaders,
|
||||
opts
|
||||
});
|
||||
} else {
|
||||
throw new Error(`Invariant: required internal revalidate method not passed to api-utils`);
|
||||
}
|
||||
} catch (err) {
|
||||
throw new Error(`Failed to revalidate ${urlPath}: ${isError(err) ? err.message : err}`);
|
||||
}
|
||||
}
|
||||
export async function apiResolver(req, res, query, resolverModule, apiContext, propagateError, dev, page) {
|
||||
const apiReq = req;
|
||||
const apiRes = res;
|
||||
try {
|
||||
var _config_api, _config_api1, _config_api2;
|
||||
if (!resolverModule) {
|
||||
res.statusCode = 404;
|
||||
res.end("Not Found");
|
||||
return;
|
||||
}
|
||||
const config = resolverModule.config || {};
|
||||
const bodyParser = ((_config_api = config.api) == null ? void 0 : _config_api.bodyParser) !== false;
|
||||
const responseLimit = ((_config_api1 = config.api) == null ? void 0 : _config_api1.responseLimit) ?? true;
|
||||
const externalResolver = ((_config_api2 = config.api) == null ? void 0 : _config_api2.externalResolver) || false;
|
||||
// Parsing of cookies
|
||||
setLazyProp({
|
||||
req: apiReq
|
||||
}, "cookies", getCookieParser(req.headers));
|
||||
// Parsing query string
|
||||
apiReq.query = query;
|
||||
// Parsing preview data
|
||||
setLazyProp({
|
||||
req: apiReq
|
||||
}, "previewData", ()=>tryGetPreviewData(req, res, apiContext, !!apiContext.multiZoneDraftMode));
|
||||
// Checking if preview mode is enabled
|
||||
setLazyProp({
|
||||
req: apiReq
|
||||
}, "preview", ()=>apiReq.previewData !== false ? true : undefined);
|
||||
// Set draftMode to the same value as preview
|
||||
setLazyProp({
|
||||
req: apiReq
|
||||
}, "draftMode", ()=>apiReq.preview);
|
||||
// Parsing of body
|
||||
if (bodyParser && !apiReq.body) {
|
||||
apiReq.body = await parseBody(apiReq, config.api && config.api.bodyParser && config.api.bodyParser.sizeLimit ? config.api.bodyParser.sizeLimit : "1mb");
|
||||
}
|
||||
let contentLength = 0;
|
||||
const maxContentLength = getMaxContentLength(responseLimit);
|
||||
const writeData = apiRes.write;
|
||||
const endResponse = apiRes.end;
|
||||
apiRes.write = (...args)=>{
|
||||
contentLength += Buffer.byteLength(args[0] || "");
|
||||
return writeData.apply(apiRes, args);
|
||||
};
|
||||
apiRes.end = (...args)=>{
|
||||
if (args.length && typeof args[0] !== "function") {
|
||||
contentLength += Buffer.byteLength(args[0] || "");
|
||||
}
|
||||
if (responseLimit && contentLength >= maxContentLength) {
|
||||
console.warn(`API response for ${req.url} exceeds ${bytes.format(maxContentLength)}. API Routes are meant to respond quickly. https://nextjs.org/docs/messages/api-routes-response-size-limit`);
|
||||
}
|
||||
return endResponse.apply(apiRes, args);
|
||||
};
|
||||
apiRes.status = (statusCode)=>sendStatusCode(apiRes, statusCode);
|
||||
apiRes.send = (data)=>sendData(apiReq, apiRes, data);
|
||||
apiRes.json = (data)=>sendJson(apiRes, data);
|
||||
apiRes.redirect = (statusOrUrl, url)=>redirect(apiRes, statusOrUrl, url);
|
||||
apiRes.setDraftMode = (options = {
|
||||
enable: true
|
||||
})=>setDraftMode(apiRes, Object.assign({}, apiContext, options));
|
||||
apiRes.setPreviewData = (data, options = {})=>setPreviewData(apiRes, data, Object.assign({}, apiContext, options));
|
||||
apiRes.clearPreviewData = (options = {})=>clearPreviewData(apiRes, options);
|
||||
apiRes.revalidate = (urlPath, opts)=>revalidate(urlPath, opts || {}, req, apiContext);
|
||||
const resolver = interopDefault(resolverModule);
|
||||
let wasPiped = false;
|
||||
if (process.env.NODE_ENV !== "production") {
|
||||
// listen for pipe event and don't show resolve warning
|
||||
res.once("pipe", ()=>wasPiped = true);
|
||||
}
|
||||
const apiRouteResult = await resolver(req, res);
|
||||
if (process.env.NODE_ENV !== "production") {
|
||||
if (typeof apiRouteResult !== "undefined") {
|
||||
if (apiRouteResult instanceof Response) {
|
||||
throw new Error('API route returned a Response object in the Node.js runtime, this is not supported. Please use `runtime: "edge"` instead: https://nextjs.org/docs/api-routes/edge-api-routes');
|
||||
}
|
||||
console.warn(`API handler should not return a value, received ${typeof apiRouteResult}.`);
|
||||
}
|
||||
if (!externalResolver && !isResSent(res) && !wasPiped) {
|
||||
console.warn(`API resolved without sending a response for ${req.url}, this may result in stalled requests.`);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
if (err instanceof ApiError) {
|
||||
sendError(apiRes, err.statusCode, err.message);
|
||||
} else {
|
||||
if (dev) {
|
||||
if (isError(err)) {
|
||||
err.page = page;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
console.error(err);
|
||||
if (propagateError) {
|
||||
throw err;
|
||||
}
|
||||
sendError(apiRes, 500, "Internal Server Error");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//# sourceMappingURL=api-resolver.js.map
|
||||
1
node_modules/next/dist/esm/server/api-utils/node/api-resolver.js.map
generated
vendored
Normal file
1
node_modules/next/dist/esm/server/api-utils/node/api-resolver.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
55
node_modules/next/dist/esm/server/api-utils/node/parse-body.js
generated
vendored
Normal file
55
node_modules/next/dist/esm/server/api-utils/node/parse-body.js
generated
vendored
Normal file
@ -0,0 +1,55 @@
|
||||
import { parse } from "next/dist/compiled/content-type";
|
||||
import isError from "../../../lib/is-error";
|
||||
import { ApiError } from "../index";
|
||||
/**
|
||||
* Parse `JSON` and handles invalid `JSON` strings
|
||||
* @param str `JSON` string
|
||||
*/ function parseJson(str) {
|
||||
if (str.length === 0) {
|
||||
// special-case empty json body, as it's a common client-side mistake
|
||||
return {};
|
||||
}
|
||||
try {
|
||||
return JSON.parse(str);
|
||||
} catch (e) {
|
||||
throw new ApiError(400, "Invalid JSON");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Parse incoming message like `json` or `urlencoded`
|
||||
* @param req request object
|
||||
*/ export async function parseBody(req, limit) {
|
||||
let contentType;
|
||||
try {
|
||||
contentType = parse(req.headers["content-type"] || "text/plain");
|
||||
} catch {
|
||||
contentType = parse("text/plain");
|
||||
}
|
||||
const { type, parameters } = contentType;
|
||||
const encoding = parameters.charset || "utf-8";
|
||||
let buffer;
|
||||
try {
|
||||
const getRawBody = require("next/dist/compiled/raw-body");
|
||||
buffer = await getRawBody(req, {
|
||||
encoding,
|
||||
limit
|
||||
});
|
||||
} catch (e) {
|
||||
if (isError(e) && e.type === "entity.too.large") {
|
||||
throw new ApiError(413, `Body exceeded ${limit} limit`);
|
||||
} else {
|
||||
throw new ApiError(400, "Invalid body");
|
||||
}
|
||||
}
|
||||
const body = buffer.toString();
|
||||
if (type === "application/json" || type === "application/ld+json") {
|
||||
return parseJson(body);
|
||||
} else if (type === "application/x-www-form-urlencoded") {
|
||||
const qs = require("querystring");
|
||||
return qs.decode(body);
|
||||
} else {
|
||||
return body;
|
||||
}
|
||||
}
|
||||
|
||||
//# sourceMappingURL=parse-body.js.map
|
||||
1
node_modules/next/dist/esm/server/api-utils/node/parse-body.js.map
generated
vendored
Normal file
1
node_modules/next/dist/esm/server/api-utils/node/parse-body.js.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../../src/server/api-utils/node/parse-body.ts"],"names":["parse","isError","ApiError","parseJson","str","length","JSON","e","parseBody","req","limit","contentType","headers","type","parameters","encoding","charset","buffer","getRawBody","require","body","toString","qs","decode"],"mappings":"AAGA,SAASA,KAAK,QAAQ,kCAAiC;AACvD,OAAOC,aAAa,wBAAuB;AAC3C,SAASC,QAAQ,QAAQ,WAAU;AAEnC;;;CAGC,GACD,SAASC,UAAUC,GAAW;IAC5B,IAAIA,IAAIC,MAAM,KAAK,GAAG;QACpB,qEAAqE;QACrE,OAAO,CAAC;IACV;IAEA,IAAI;QACF,OAAOC,KAAKN,KAAK,CAACI;IACpB,EAAE,OAAOG,GAAG;QACV,MAAM,IAAIL,SAAS,KAAK;IAC1B;AACF;AAEA;;;CAGC,GACD,OAAO,eAAeM,UACpBC,GAAoB,EACpBC,KAAgB;IAEhB,IAAIC;IACJ,IAAI;QACFA,cAAcX,MAAMS,IAAIG,OAAO,CAAC,eAAe,IAAI;IACrD,EAAE,OAAM;QACND,cAAcX,MAAM;IACtB;IACA,MAAM,EAAEa,IAAI,EAAEC,UAAU,EAAE,GAAGH;IAC7B,MAAMI,WAAWD,WAAWE,OAAO,IAAI;IAEvC,IAAIC;IAEJ,IAAI;QACF,MAAMC,aACJC,QAAQ;QACVF,SAAS,MAAMC,WAAWT,KAAK;YAAEM;YAAUL;QAAM;IACnD,EAAE,OAAOH,GAAG;QACV,IAAIN,QAAQM,MAAMA,EAAEM,IAAI,KAAK,oBAAoB;YAC/C,MAAM,IAAIX,SAAS,KAAK,CAAC,cAAc,EAAEQ,MAAM,MAAM,CAAC;QACxD,OAAO;YACL,MAAM,IAAIR,SAAS,KAAK;QAC1B;IACF;IAEA,MAAMkB,OAAOH,OAAOI,QAAQ;IAE5B,IAAIR,SAAS,sBAAsBA,SAAS,uBAAuB;QACjE,OAAOV,UAAUiB;IACnB,OAAO,IAAIP,SAAS,qCAAqC;QACvD,MAAMS,KAAKH,QAAQ;QACnB,OAAOG,GAAGC,MAAM,CAACH;IACnB,OAAO;QACL,OAAOA;IACT;AACF"}
|
||||
76
node_modules/next/dist/esm/server/api-utils/node/try-get-preview-data.js
generated
vendored
Normal file
76
node_modules/next/dist/esm/server/api-utils/node/try-get-preview-data.js
generated
vendored
Normal file
@ -0,0 +1,76 @@
|
||||
import { checkIsOnDemandRevalidate } from "../.";
|
||||
import { clearPreviewData, COOKIE_NAME_PRERENDER_BYPASS, COOKIE_NAME_PRERENDER_DATA, SYMBOL_PREVIEW_DATA } from "../index";
|
||||
import { RequestCookies } from "../../web/spec-extension/cookies";
|
||||
import { HeadersAdapter } from "../../web/spec-extension/adapters/headers";
|
||||
export function tryGetPreviewData(req, res, options, multiZoneDraftMode) {
|
||||
var _cookies_get, _cookies_get1;
|
||||
// if an On-Demand revalidation is being done preview mode
|
||||
// is disabled
|
||||
if (options && checkIsOnDemandRevalidate(req, options).isOnDemandRevalidate) {
|
||||
return false;
|
||||
}
|
||||
// Read cached preview data if present
|
||||
// TODO: use request metadata instead of a symbol
|
||||
if (SYMBOL_PREVIEW_DATA in req) {
|
||||
return req[SYMBOL_PREVIEW_DATA];
|
||||
}
|
||||
const headers = HeadersAdapter.from(req.headers);
|
||||
const cookies = new RequestCookies(headers);
|
||||
const previewModeId = (_cookies_get = cookies.get(COOKIE_NAME_PRERENDER_BYPASS)) == null ? void 0 : _cookies_get.value;
|
||||
const tokenPreviewData = (_cookies_get1 = cookies.get(COOKIE_NAME_PRERENDER_DATA)) == null ? void 0 : _cookies_get1.value;
|
||||
// Case: preview mode cookie set but data cookie is not set
|
||||
if (previewModeId && !tokenPreviewData && previewModeId === options.previewModeId) {
|
||||
// This is "Draft Mode" which doesn't use
|
||||
// previewData, so we return an empty object
|
||||
// for backwards compat with "Preview Mode".
|
||||
const data = {};
|
||||
Object.defineProperty(req, SYMBOL_PREVIEW_DATA, {
|
||||
value: data,
|
||||
enumerable: false
|
||||
});
|
||||
return data;
|
||||
}
|
||||
// Case: neither cookie is set.
|
||||
if (!previewModeId && !tokenPreviewData) {
|
||||
return false;
|
||||
}
|
||||
// Case: one cookie is set, but not the other.
|
||||
if (!previewModeId || !tokenPreviewData) {
|
||||
if (!multiZoneDraftMode) {
|
||||
clearPreviewData(res);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
// Case: preview session is for an old build.
|
||||
if (previewModeId !== options.previewModeId) {
|
||||
if (!multiZoneDraftMode) {
|
||||
clearPreviewData(res);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
let encryptedPreviewData;
|
||||
try {
|
||||
const jsonwebtoken = require("next/dist/compiled/jsonwebtoken");
|
||||
encryptedPreviewData = jsonwebtoken.verify(tokenPreviewData, options.previewModeSigningKey);
|
||||
} catch {
|
||||
// TODO: warn
|
||||
clearPreviewData(res);
|
||||
return false;
|
||||
}
|
||||
const { decryptWithSecret } = require("../../crypto-utils");
|
||||
const decryptedPreviewData = decryptWithSecret(Buffer.from(options.previewModeEncryptionKey), encryptedPreviewData.data);
|
||||
try {
|
||||
// TODO: strict runtime type checking
|
||||
const data = JSON.parse(decryptedPreviewData);
|
||||
// Cache lookup
|
||||
Object.defineProperty(req, SYMBOL_PREVIEW_DATA, {
|
||||
value: data,
|
||||
enumerable: false
|
||||
});
|
||||
return data;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//# sourceMappingURL=try-get-preview-data.js.map
|
||||
1
node_modules/next/dist/esm/server/api-utils/node/try-get-preview-data.js.map
generated
vendored
Normal file
1
node_modules/next/dist/esm/server/api-utils/node/try-get-preview-data.js.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../../src/server/api-utils/node/try-get-preview-data.ts"],"names":["checkIsOnDemandRevalidate","clearPreviewData","COOKIE_NAME_PRERENDER_BYPASS","COOKIE_NAME_PRERENDER_DATA","SYMBOL_PREVIEW_DATA","RequestCookies","HeadersAdapter","tryGetPreviewData","req","res","options","multiZoneDraftMode","cookies","isOnDemandRevalidate","headers","from","previewModeId","get","value","tokenPreviewData","data","Object","defineProperty","enumerable","encryptedPreviewData","jsonwebtoken","require","verify","previewModeSigningKey","decryptWithSecret","decryptedPreviewData","Buffer","previewModeEncryptionKey","JSON","parse"],"mappings":"AAEA,SAASA,yBAAyB,QAAQ,OAAM;AAKhD,SACEC,gBAAgB,EAChBC,4BAA4B,EAC5BC,0BAA0B,EAC1BC,mBAAmB,QACd,WAAU;AACjB,SAASC,cAAc,QAAQ,mCAAkC;AACjE,SAASC,cAAc,QAAQ,4CAA2C;AAE1E,OAAO,SAASC,kBACdC,GAAgD,EAChDC,GAAsC,EACtCC,OAA0B,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EoB,iBAAiB,EAAE,GACzBH,QAAQ;IACV,MAAMI,uBAAuBD,kBAC3BE,OAAOhB,IAAI,CAACL,QAAQsB,wBAAwB,GAC5CR,qBAAqBJ,IAAI;IAG3B,IAAI;QACF,qCAAqC;QACrC,MAAMA,OAAOa,KAAKC,KAAK,CAACJ;QACxB,eAAe;QACfT,OAAOC,cAAc,CAACd,KAAKJ,qBAAqB;YAC9Cc,OAAOE;YACPG,YAAY;QACd;QACA,OAAOH;IACT,EAAE,OAAM;QACN,OAAO;IACT;AACF"}
|
||||
7
node_modules/next/dist/esm/server/api-utils/web.js
generated
vendored
Normal file
7
node_modules/next/dist/esm/server/api-utils/web.js
generated
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
// Buffer.byteLength polyfill in the Edge runtime, with only utf8 strings
|
||||
// supported at the moment.
|
||||
export function byteLength(payload) {
|
||||
return new TextEncoder().encode(payload).buffer.byteLength;
|
||||
}
|
||||
|
||||
//# sourceMappingURL=web.js.map
|
||||
1
node_modules/next/dist/esm/server/api-utils/web.js.map
generated
vendored
Normal file
1
node_modules/next/dist/esm/server/api-utils/web.js.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../src/server/api-utils/web.ts"],"names":["byteLength","payload","TextEncoder","encode","buffer"],"mappings":"AAAA,yEAAyE;AACzE,2BAA2B;AAC3B,OAAO,SAASA,WAAWC,OAAe;IACxC,OAAO,IAAIC,cAAcC,MAAM,CAACF,SAASG,MAAM,CAACJ,UAAU;AAC5D"}
|
||||
Reference in New Issue
Block a user