@makeswift/runtime 0.16.0-canary.5 → 0.16.0-canary.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/next/api-handler/handlers/manifest.js +1 -1
- package/dist/cjs/next/api-handler/handlers/proxy-preview-mode.js +1 -1
- package/dist/cjs/next/api-handler/handlers/proxy-preview-mode.js.map +1 -1
- package/dist/esm/next/api-handler/handlers/manifest.js +1 -1
- package/dist/esm/next/api-handler/handlers/proxy-preview-mode.js +1 -1
- package/dist/esm/next/api-handler/handlers/proxy-preview-mode.js.map +1 -1
- package/package.json +1 -1
|
@@ -36,7 +36,7 @@ async function handler(...args) {
|
|
|
36
36
|
const supportsPreviewMode = (0, import_ts_pattern.match)(args).with(routeHandlerPattern, () => false).with(apiRoutePattern, () => true).exhaustive();
|
|
37
37
|
const supportsDraftMode = (0, import_ts_pattern.match)(args).with(routeHandlerPattern, () => true).with(apiRoutePattern, () => false).exhaustive();
|
|
38
38
|
const body = {
|
|
39
|
-
version: "0.16.0-canary.
|
|
39
|
+
version: "0.16.0-canary.6",
|
|
40
40
|
previewMode: supportsPreviewMode,
|
|
41
41
|
draftMode: supportsDraftMode,
|
|
42
42
|
interactionMode: true,
|
|
@@ -94,7 +94,7 @@ async function proxyPreviewModeApiRouteHandler(req, res, { apiKey }) {
|
|
|
94
94
|
res.removeHeader("content-length");
|
|
95
95
|
}
|
|
96
96
|
const arrayBuffer = await response.arrayBuffer();
|
|
97
|
-
res.write(arrayBuffer);
|
|
97
|
+
res.write(new Uint8Array(arrayBuffer));
|
|
98
98
|
res.end();
|
|
99
99
|
}
|
|
100
100
|
//# sourceMappingURL=proxy-preview-mode.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/next/api-handler/handlers/proxy-preview-mode.ts"],"sourcesContent":["import { NextApiRequest, NextApiResponse } from 'next'\nimport { MakeswiftPreviewData, MakeswiftSiteVersion } from '../../preview-mode'\nimport { NextRequest, NextResponse } from 'next/server'\nimport { P, match } from 'ts-pattern'\n\ntype Context = { params: { [key: string]: string | string[] } }\n\ntype ProxyPreviewModeError = string\n\ntype ProxyResponse = { __brand: 'ProxyResponse' }\n\nexport type ProxyPreviewModeResponse = ProxyPreviewModeError | ProxyResponse\n\ntype ProxyPreviewModeHandlerArgs =\n | [request: NextRequest, context: Context, params: { apiKey: string }]\n | [\n req: NextApiRequest,\n res: NextApiResponse<ProxyPreviewModeResponse>,\n params: { apiKey: string },\n ]\n\nconst routeHandlerPattern = [P.instanceOf(Request), P.any, P.any] as const\nconst apiRoutePattern = [P.any, P.any, P.any] as const\n\nfunction mapRequestHeadersToHeaders(requestHeaders: NextApiRequest['headers']): Headers {\n const headers = new Headers()\n\n Object.entries(requestHeaders).forEach(([key, value]) => {\n match(value)\n .with(P.array(P.string), value => value.map(val => headers.append(key, val)))\n .with(P.string, value => headers.set(key, value))\n })\n\n return headers\n}\n\nfunction mapRequestToProxyUrl(req: NextApiRequest): URL {\n const isForwardedProtoHttps = match(req.headers['X-Forwarded-Proto'])\n .with(P.string, x => x.split(','))\n .with(P.array(P.string), x => x)\n .otherwise(() => [])\n .includes('https')\n\n const isForwardedSSL = match(req.headers['X-Forwarded-SSL'])\n .with('on', () => true)\n .otherwise(() => false)\n\n const proto = isForwardedProtoHttps || isForwardedSSL ? 'https' : 'http'\n\n return new URL(`${proto}://${req.headers.host}${req.url}`)\n}\n\nexport default async function proxyPreviewMode(\n request: NextRequest,\n context: Context,\n { apiKey }: { apiKey: string },\n): Promise<NextResponse<ProxyPreviewModeResponse>>\nexport default async function proxyPreviewMode(\n req: NextApiRequest,\n res: NextApiResponse<ProxyPreviewModeResponse>,\n { apiKey }: { apiKey: string },\n): Promise<void>\nexport default async function proxyPreviewMode(\n ...args: ProxyPreviewModeHandlerArgs\n): Promise<NextResponse<ProxyPreviewModeResponse> | void> {\n return match(args)\n .with(routeHandlerPattern, args => proxyPreviewModeRouteHandler(...args))\n .with(apiRoutePattern, args => proxyPreviewModeApiRouteHandler(...args))\n .exhaustive()\n}\n\nasync function proxyPreviewModeRouteHandler(\n _request: NextRequest,\n _context: Context,\n {}: { apiKey: string },\n): Promise<NextResponse<ProxyPreviewModeResponse>> {\n const message =\n 'Cannot request preview endpoint from an API handler registered in `app`. Move your Makeswift API handler to the `pages/api` directory'\n console.error(message)\n return NextResponse.json(message, { status: 500 })\n}\n\nasync function proxyPreviewModeApiRouteHandler(\n req: NextApiRequest,\n res: NextApiResponse<ProxyPreviewModeResponse>,\n { apiKey }: { apiKey: string },\n): Promise<void> {\n if (req.query.secret !== apiKey) return res.status(401).send('Unauthorized')\n if (req.headers.host == null) return res.status(400).send('Bad Request')\n\n // TODO: This is a hack to get the locale from the request.\n // Next.js strips the locale from the req.url, and there's no official way to get the locale\n // from an API route: https://github.com/vercel/next.js/discussions/21798.\n // The current workaround is to get the locale from an internal object: RequestMeta,\n // https://github.com/vercel/next.js/blob/a0d1d728b9003f12c9df6c5e9a33bc4c33cef0ab/packages/next/src/server/request-meta.ts\n // One possible way to properly fix this is by updating how we do preview mode. For example,\n // by using partitioned cookies instead of a proxy.\n const NextRequestMetaSymbol = Reflect.ownKeys(req).find(\n key =>\n key.toString() === 'Symbol(NextRequestMeta)' ||\n key.toString() === 'Symbol(NextInternalRequestMeta)',\n ) as keyof NextApiRequest | undefined\n\n if (NextRequestMetaSymbol) {\n const nextRequestMeta = req[NextRequestMetaSymbol]\n const initUrl = nextRequestMeta?.__NEXT_INIT_URL ?? nextRequestMeta?.initURL\n const isLocaleStripped =\n nextRequestMeta?.__nextStrippedLocale ?? nextRequestMeta?.didStripLocale\n\n try {\n if (isLocaleStripped && initUrl) req.url = new URL(initUrl).pathname\n } catch {}\n }\n\n const proxyHeaders = mapRequestHeadersToHeaders(req.headers)\n const proxyUrl = mapRequestToProxyUrl(req)\n\n proxyUrl.searchParams.delete('x-makeswift-preview-mode')\n proxyHeaders.delete('x-makeswift-preview-mode')\n // The following headers are Next.js-specific and are removed to prevent Next.js from\n // short-circuiting requests, breaking routing.\n proxyHeaders.delete('x-invoke-path')\n proxyHeaders.delete('x-invoke-query')\n\n const previewData: MakeswiftPreviewData = {\n makeswift: true,\n // This will eventually be dynamic\n siteVersion: MakeswiftSiteVersion.Working,\n }\n\n const setCookie = res.setPreviewData(previewData).getHeader('set-cookie')\n res.removeHeader('set-cookie')\n\n if (!Array.isArray(setCookie)) return res.status(500).send('Internal Server Error')\n\n setCookie.forEach((cookie) => proxyHeaders.append('cookie', cookie))\n\n const response = await fetch(proxyUrl, {\n headers: proxyHeaders,\n });\n\n response.headers.forEach((value, name) => {\n res.setHeader(name, value);\n })\n\n res.statusCode = response.status;\n res.statusMessage = response.statusText\n\n // `fetch` automatically decompresses the response, but the response headers will keep the\n // `content-encoding` and `content-length` headers. This will cause decoding issues if the client\n // attempts to decompress the response again. To prevent this, we remove these headers.\n //\n // See https://github.com/nodejs/undici/issues/2514.\n if (res.hasHeader('content-encoding')) {\n res.removeHeader('content-encoding')\n res.removeHeader('content-length')\n }\n\n const arrayBuffer = await response.arrayBuffer()\n\n res.write(arrayBuffer)\n res.end()\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,0BAA2D;AAC3D,oBAA0C;AAC1C,wBAAyB;AAkBzB,MAAM,sBAAsB,CAAC,oBAAE,WAAW,OAAO,GAAG,oBAAE,KAAK,oBAAE,GAAG;AAChE,MAAM,kBAAkB,CAAC,oBAAE,KAAK,oBAAE,KAAK,oBAAE,GAAG;AAE5C,SAAS,2BAA2B,gBAAoD;AACtF,QAAM,UAAU,IAAI,QAAQ;AAE5B,SAAO,QAAQ,cAAc,EAAE,QAAQ,CAAC,CAAC,KAAK,KAAK,MAAM;AACvD,iCAAM,KAAK,EACR,KAAK,oBAAE,MAAM,oBAAE,MAAM,GAAG,CAAAA,WAASA,OAAM,IAAI,SAAO,QAAQ,OAAO,KAAK,GAAG,CAAC,CAAC,EAC3E,KA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NextApiRequest, NextApiResponse } from 'next'\nimport { MakeswiftPreviewData, MakeswiftSiteVersion } from '../../preview-mode'\nimport { NextRequest, NextResponse } from 'next/server'\nimport { P, match } from 'ts-pattern'\n\ntype Context = { params: { [key: string]: string | string[] } }\n\ntype ProxyPreviewModeError = string\n\ntype ProxyResponse = { __brand: 'ProxyResponse' }\n\nexport type ProxyPreviewModeResponse = ProxyPreviewModeError | ProxyResponse\n\ntype ProxyPreviewModeHandlerArgs =\n | [request: NextRequest, context: Context, params: { apiKey: string }]\n | [\n req: NextApiRequest,\n res: NextApiResponse<ProxyPreviewModeResponse>,\n params: { apiKey: string },\n ]\n\nconst routeHandlerPattern = [P.instanceOf(Request), P.any, P.any] as const\nconst apiRoutePattern = [P.any, P.any, P.any] as const\n\nfunction mapRequestHeadersToHeaders(requestHeaders: NextApiRequest['headers']): Headers {\n const headers = new Headers()\n\n Object.entries(requestHeaders).forEach(([key, value]) => {\n match(value)\n .with(P.array(P.string), value => value.map(val => headers.append(key, val)))\n .with(P.string, value => headers.set(key, value))\n })\n\n return headers\n}\n\nfunction mapRequestToProxyUrl(req: NextApiRequest): URL {\n const isForwardedProtoHttps = match(req.headers['X-Forwarded-Proto'])\n .with(P.string, x => x.split(','))\n .with(P.array(P.string), x => x)\n .otherwise(() => [])\n .includes('https')\n\n const isForwardedSSL = match(req.headers['X-Forwarded-SSL'])\n .with('on', () => true)\n .otherwise(() => false)\n\n const proto = isForwardedProtoHttps || isForwardedSSL ? 'https' : 'http'\n\n return new URL(`${proto}://${req.headers.host}${req.url}`)\n}\n\nexport default async function proxyPreviewMode(\n request: NextRequest,\n context: Context,\n { apiKey }: { apiKey: string },\n): Promise<NextResponse<ProxyPreviewModeResponse>>\nexport default async function proxyPreviewMode(\n req: NextApiRequest,\n res: NextApiResponse<ProxyPreviewModeResponse>,\n { apiKey }: { apiKey: string },\n): Promise<void>\nexport default async function proxyPreviewMode(\n ...args: ProxyPreviewModeHandlerArgs\n): Promise<NextResponse<ProxyPreviewModeResponse> | void> {\n return match(args)\n .with(routeHandlerPattern, args => proxyPreviewModeRouteHandler(...args))\n .with(apiRoutePattern, args => proxyPreviewModeApiRouteHandler(...args))\n .exhaustive()\n}\n\nasync function proxyPreviewModeRouteHandler(\n _request: NextRequest,\n _context: Context,\n {}: { apiKey: string },\n): Promise<NextResponse<ProxyPreviewModeResponse>> {\n const message =\n 'Cannot request preview endpoint from an API handler registered in `app`. Move your Makeswift API handler to the `pages/api` directory'\n console.error(message)\n return NextResponse.json(message, { status: 500 })\n}\n\nasync function proxyPreviewModeApiRouteHandler(\n req: NextApiRequest,\n res: NextApiResponse<ProxyPreviewModeResponse>,\n { apiKey }: { apiKey: string },\n): Promise<void> {\n if (req.query.secret !== apiKey) return res.status(401).send('Unauthorized')\n if (req.headers.host == null) return res.status(400).send('Bad Request')\n\n // TODO: This is a hack to get the locale from the request.\n // Next.js strips the locale from the req.url, and there's no official way to get the locale\n // from an API route: https://github.com/vercel/next.js/discussions/21798.\n // The current workaround is to get the locale from an internal object: RequestMeta,\n // https://github.com/vercel/next.js/blob/a0d1d728b9003f12c9df6c5e9a33bc4c33cef0ab/packages/next/src/server/request-meta.ts\n // One possible way to properly fix this is by updating how we do preview mode. For example,\n // by using partitioned cookies instead of a proxy.\n const NextRequestMetaSymbol = Reflect.ownKeys(req).find(\n key =>\n key.toString() === 'Symbol(NextRequestMeta)' ||\n key.toString() === 'Symbol(NextInternalRequestMeta)',\n ) as keyof NextApiRequest | undefined\n\n if (NextRequestMetaSymbol) {\n const nextRequestMeta = req[NextRequestMetaSymbol]\n const initUrl = nextRequestMeta?.__NEXT_INIT_URL ?? nextRequestMeta?.initURL\n const isLocaleStripped =\n nextRequestMeta?.__nextStrippedLocale ?? nextRequestMeta?.didStripLocale\n\n try {\n if (isLocaleStripped && initUrl) req.url = new URL(initUrl).pathname\n } catch {}\n }\n\n const proxyHeaders = mapRequestHeadersToHeaders(req.headers)\n const proxyUrl = mapRequestToProxyUrl(req)\n\n proxyUrl.searchParams.delete('x-makeswift-preview-mode')\n proxyHeaders.delete('x-makeswift-preview-mode')\n // The following headers are Next.js-specific and are removed to prevent Next.js from\n // short-circuiting requests, breaking routing.\n proxyHeaders.delete('x-invoke-path')\n proxyHeaders.delete('x-invoke-query')\n\n const previewData: MakeswiftPreviewData = {\n makeswift: true,\n // This will eventually be dynamic\n siteVersion: MakeswiftSiteVersion.Working,\n }\n\n const setCookie = res.setPreviewData(previewData).getHeader('set-cookie')\n res.removeHeader('set-cookie')\n\n if (!Array.isArray(setCookie)) return res.status(500).send('Internal Server Error')\n\n setCookie.forEach((cookie) => proxyHeaders.append('cookie', cookie))\n\n const response = await fetch(proxyUrl, {\n headers: proxyHeaders,\n });\n\n response.headers.forEach((value, name) => {\n res.setHeader(name, value);\n })\n\n res.statusCode = response.status;\n res.statusMessage = response.statusText\n\n // `fetch` automatically decompresses the response, but the response headers will keep the\n // `content-encoding` and `content-length` headers. This will cause decoding issues if the client\n // attempts to decompress the response again. To prevent this, we remove these headers.\n //\n // See https://github.com/nodejs/undici/issues/2514.\n if (res.hasHeader('content-encoding')) {\n res.removeHeader('content-encoding')\n res.removeHeader('content-length')\n }\n\n const arrayBuffer = await response.arrayBuffer()\n\n res.write(new Uint8Array(arrayBuffer))\n res.end()\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,0BAA2D;AAC3D,oBAA0C;AAC1C,wBAAyB;AAkBzB,MAAM,sBAAsB,CAAC,oBAAE,WAAW,OAAO,GAAG,oBAAE,KAAK,oBAAE,GAAG;AAChE,MAAM,kBAAkB,CAAC,oBAAE,KAAK,oBAAE,KAAK,oBAAE,GAAG;AAE5C,SAAS,2BAA2B,gBAAoD;AACtF,QAAM,UAAU,IAAI,QAAQ;AAE5B,SAAO,QAAQ,cAAc,EAAE,QAAQ,CAAC,CAAC,KAAK,KAAK,MAAM;AACvD,iCAAM,KAAK,EACR,KAAK,oBAAE,MAAM,oBAAE,MAAM,GAA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I,WAAW,WAAW,CAAC;AACrC,MAAI,IAAI;AACV;","names":["value","args"]}
|
|
@@ -13,7 +13,7 @@ async function handler(...args) {
|
|
|
13
13
|
const supportsPreviewMode = match(args).with(routeHandlerPattern, () => false).with(apiRoutePattern, () => true).exhaustive();
|
|
14
14
|
const supportsDraftMode = match(args).with(routeHandlerPattern, () => true).with(apiRoutePattern, () => false).exhaustive();
|
|
15
15
|
const body = {
|
|
16
|
-
version: "0.16.0-canary.
|
|
16
|
+
version: "0.16.0-canary.6",
|
|
17
17
|
previewMode: supportsPreviewMode,
|
|
18
18
|
draftMode: supportsDraftMode,
|
|
19
19
|
interactionMode: true,
|
|
@@ -71,7 +71,7 @@ async function proxyPreviewModeApiRouteHandler(req, res, { apiKey }) {
|
|
|
71
71
|
res.removeHeader("content-length");
|
|
72
72
|
}
|
|
73
73
|
const arrayBuffer = await response.arrayBuffer();
|
|
74
|
-
res.write(arrayBuffer);
|
|
74
|
+
res.write(new Uint8Array(arrayBuffer));
|
|
75
75
|
res.end();
|
|
76
76
|
}
|
|
77
77
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/next/api-handler/handlers/proxy-preview-mode.ts"],"sourcesContent":["import { NextApiRequest, NextApiResponse } from 'next'\nimport { MakeswiftPreviewData, MakeswiftSiteVersion } from '../../preview-mode'\nimport { NextRequest, NextResponse } from 'next/server'\nimport { P, match } from 'ts-pattern'\n\ntype Context = { params: { [key: string]: string | string[] } }\n\ntype ProxyPreviewModeError = string\n\ntype ProxyResponse = { __brand: 'ProxyResponse' }\n\nexport type ProxyPreviewModeResponse = ProxyPreviewModeError | ProxyResponse\n\ntype ProxyPreviewModeHandlerArgs =\n | [request: NextRequest, context: Context, params: { apiKey: string }]\n | [\n req: NextApiRequest,\n res: NextApiResponse<ProxyPreviewModeResponse>,\n params: { apiKey: string },\n ]\n\nconst routeHandlerPattern = [P.instanceOf(Request), P.any, P.any] as const\nconst apiRoutePattern = [P.any, P.any, P.any] as const\n\nfunction mapRequestHeadersToHeaders(requestHeaders: NextApiRequest['headers']): Headers {\n const headers = new Headers()\n\n Object.entries(requestHeaders).forEach(([key, value]) => {\n match(value)\n .with(P.array(P.string), value => value.map(val => headers.append(key, val)))\n .with(P.string, value => headers.set(key, value))\n })\n\n return headers\n}\n\nfunction mapRequestToProxyUrl(req: NextApiRequest): URL {\n const isForwardedProtoHttps = match(req.headers['X-Forwarded-Proto'])\n .with(P.string, x => x.split(','))\n .with(P.array(P.string), x => x)\n .otherwise(() => [])\n .includes('https')\n\n const isForwardedSSL = match(req.headers['X-Forwarded-SSL'])\n .with('on', () => true)\n .otherwise(() => false)\n\n const proto = isForwardedProtoHttps || isForwardedSSL ? 'https' : 'http'\n\n return new URL(`${proto}://${req.headers.host}${req.url}`)\n}\n\nexport default async function proxyPreviewMode(\n request: NextRequest,\n context: Context,\n { apiKey }: { apiKey: string },\n): Promise<NextResponse<ProxyPreviewModeResponse>>\nexport default async function proxyPreviewMode(\n req: NextApiRequest,\n res: NextApiResponse<ProxyPreviewModeResponse>,\n { apiKey }: { apiKey: string },\n): Promise<void>\nexport default async function proxyPreviewMode(\n ...args: ProxyPreviewModeHandlerArgs\n): Promise<NextResponse<ProxyPreviewModeResponse> | void> {\n return match(args)\n .with(routeHandlerPattern, args => proxyPreviewModeRouteHandler(...args))\n .with(apiRoutePattern, args => proxyPreviewModeApiRouteHandler(...args))\n .exhaustive()\n}\n\nasync function proxyPreviewModeRouteHandler(\n _request: NextRequest,\n _context: Context,\n {}: { apiKey: string },\n): Promise<NextResponse<ProxyPreviewModeResponse>> {\n const message =\n 'Cannot request preview endpoint from an API handler registered in `app`. Move your Makeswift API handler to the `pages/api` directory'\n console.error(message)\n return NextResponse.json(message, { status: 500 })\n}\n\nasync function proxyPreviewModeApiRouteHandler(\n req: NextApiRequest,\n res: NextApiResponse<ProxyPreviewModeResponse>,\n { apiKey }: { apiKey: string },\n): Promise<void> {\n if (req.query.secret !== apiKey) return res.status(401).send('Unauthorized')\n if (req.headers.host == null) return res.status(400).send('Bad Request')\n\n // TODO: This is a hack to get the locale from the request.\n // Next.js strips the locale from the req.url, and there's no official way to get the locale\n // from an API route: https://github.com/vercel/next.js/discussions/21798.\n // The current workaround is to get the locale from an internal object: RequestMeta,\n // https://github.com/vercel/next.js/blob/a0d1d728b9003f12c9df6c5e9a33bc4c33cef0ab/packages/next/src/server/request-meta.ts\n // One possible way to properly fix this is by updating how we do preview mode. For example,\n // by using partitioned cookies instead of a proxy.\n const NextRequestMetaSymbol = Reflect.ownKeys(req).find(\n key =>\n key.toString() === 'Symbol(NextRequestMeta)' ||\n key.toString() === 'Symbol(NextInternalRequestMeta)',\n ) as keyof NextApiRequest | undefined\n\n if (NextRequestMetaSymbol) {\n const nextRequestMeta = req[NextRequestMetaSymbol]\n const initUrl = nextRequestMeta?.__NEXT_INIT_URL ?? nextRequestMeta?.initURL\n const isLocaleStripped =\n nextRequestMeta?.__nextStrippedLocale ?? nextRequestMeta?.didStripLocale\n\n try {\n if (isLocaleStripped && initUrl) req.url = new URL(initUrl).pathname\n } catch {}\n }\n\n const proxyHeaders = mapRequestHeadersToHeaders(req.headers)\n const proxyUrl = mapRequestToProxyUrl(req)\n\n proxyUrl.searchParams.delete('x-makeswift-preview-mode')\n proxyHeaders.delete('x-makeswift-preview-mode')\n // The following headers are Next.js-specific and are removed to prevent Next.js from\n // short-circuiting requests, breaking routing.\n proxyHeaders.delete('x-invoke-path')\n proxyHeaders.delete('x-invoke-query')\n\n const previewData: MakeswiftPreviewData = {\n makeswift: true,\n // This will eventually be dynamic\n siteVersion: MakeswiftSiteVersion.Working,\n }\n\n const setCookie = res.setPreviewData(previewData).getHeader('set-cookie')\n res.removeHeader('set-cookie')\n\n if (!Array.isArray(setCookie)) return res.status(500).send('Internal Server Error')\n\n setCookie.forEach((cookie) => proxyHeaders.append('cookie', cookie))\n\n const response = await fetch(proxyUrl, {\n headers: proxyHeaders,\n });\n\n response.headers.forEach((value, name) => {\n res.setHeader(name, value);\n })\n\n res.statusCode = response.status;\n res.statusMessage = response.statusText\n\n // `fetch` automatically decompresses the response, but the response headers will keep the\n // `content-encoding` and `content-length` headers. This will cause decoding issues if the client\n // attempts to decompress the response again. To prevent this, we remove these headers.\n //\n // See https://github.com/nodejs/undici/issues/2514.\n if (res.hasHeader('content-encoding')) {\n res.removeHeader('content-encoding')\n res.removeHeader('content-length')\n }\n\n const arrayBuffer = await response.arrayBuffer()\n\n res.write(arrayBuffer)\n res.end()\n}\n"],"mappings":"AACA,SAA+B,4BAA4B;AAC3D,SAAsB,oBAAoB;AAC1C,SAAS,GAAG,aAAa;AAkBzB,MAAM,sBAAsB,CAAC,EAAE,WAAW,OAAO,GAAG,EAAE,KAAK,EAAE,GAAG;AAChE,MAAM,kBAAkB,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG;AAE5C,SAAS,2BAA2B,gBAAoD;AACtF,QAAM,UAAU,IAAI,QAAQ;AAE5B,SAAO,QAAQ,cAAc,EAAE,QAAQ,CAAC,CAAC,KAAK,KAAK,MAAM;AACvD,UAAM,KAAK,EACR,KAAK,EAAE,MAAM,EAAE,MAAM,GAAG,CAAAA,WAASA,OAAM,IAAI,SAAO,QAAQ,OAAO,KAAK,GAAG,CAAC,CAAC,EAC3E,KAAK,EAAE,QAAQ,CAAAA,WAAS,QAAQ,IAAI,KAAKA,MAAK,CAAC;AAAA,EACpD,CAAC;AAED,SAAO;AACT;AAEA,SAAS,qBAAqB,KAA0B;AACtD,QAAM,wBAAwB,MAAM,IAAI,QAAQ,mBAAmB,CAAC,EACjE,KAAK,EAAE,QAAQ,OAAK,EAAE,MAAM,GAAG,CAAC,EAChC,KAAK,EAAE,MAAM,EAAE,MAAM,GAAG,OAAK,CAAC,EAC9B,UAAU,MAAM,CAAC,CAAC,EAClB,SAAS,OAAO;AAEnB,QAAM,iBAAiB,MAAM,IAAI,QAAQ,iBAAiB,CAAC,EACxD,KAAK,MAAM,MAAM,IAAI,EACrB,UAAU,M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,OAAO,gBAAgB;AAEpC,QAAM,cAAoC;AAAA,IACxC,WAAW;AAAA;AAAA,IAEX,aAAa,qBAAqB;AAAA,EACpC;AAEA,QAAM,YAAY,IAAI,eAAe,WAAW,EAAE,UAAU,YAAY;AACxE,MAAI,aAAa,YAAY;AAE7B,MAAI,CAAC,MAAM,QAAQ,SAAS;AAAG,WAAO,IAAI,OAAO,GAAG,EAAE,KAAK,uBAAuB;AAElF,YAAU,QAAQ,CAAC,WAAW,aAAa,OAAO,UAAU,MAAM,CAAC;AAEnE,QAAM,WAAW,MAAM,MAAM,UAAU;AAAA,IACrC,SAAS;AAAA,EACX,CAAC;AAED,WAAS,QAAQ,QAAQ,CAAC,OAAO,SAAS;AACxC,QAAI,UAAU,MAAM,KAAK;AAAA,EAC3B,CAAC;AAED,MAAI,aAAa,SAAS;AAC1B,MAAI,gBAAgB,SAAS;AAO7B,MAAI,IAAI,UAAU,kBAAkB,GAAG;AACrC,QAAI,aAAa,kBAAkB;AACnC,QAAI,aAAa,gBAAgB;AAAA,EACnC;AAEA,QAAM,cAAc,MAAM,SAAS,YAAY;AAE/C,MAAI,MAAM,WAAW;
|
|
1
|
+
{"version":3,"sources":["../../../../../src/next/api-handler/handlers/proxy-preview-mode.ts"],"sourcesContent":["import { NextApiRequest, NextApiResponse } from 'next'\nimport { MakeswiftPreviewData, MakeswiftSiteVersion } from '../../preview-mode'\nimport { NextRequest, NextResponse } from 'next/server'\nimport { P, match } from 'ts-pattern'\n\ntype Context = { params: { [key: string]: string | string[] } }\n\ntype ProxyPreviewModeError = string\n\ntype ProxyResponse = { __brand: 'ProxyResponse' }\n\nexport type ProxyPreviewModeResponse = ProxyPreviewModeError | ProxyResponse\n\ntype ProxyPreviewModeHandlerArgs =\n | [request: NextRequest, context: Context, params: { apiKey: string }]\n | [\n req: NextApiRequest,\n res: NextApiResponse<ProxyPreviewModeResponse>,\n params: { apiKey: string },\n ]\n\nconst routeHandlerPattern = [P.instanceOf(Request), P.any, P.any] as const\nconst apiRoutePattern = [P.any, P.any, P.any] as const\n\nfunction mapRequestHeadersToHeaders(requestHeaders: NextApiRequest['headers']): Headers {\n const headers = new Headers()\n\n Object.entries(requestHeaders).forEach(([key, value]) => {\n match(value)\n .with(P.array(P.string), value => value.map(val => headers.append(key, val)))\n .with(P.string, value => headers.set(key, value))\n })\n\n return headers\n}\n\nfunction mapRequestToProxyUrl(req: NextApiRequest): URL {\n const isForwardedProtoHttps = match(req.headers['X-Forwarded-Proto'])\n .with(P.string, x => x.split(','))\n .with(P.array(P.string), x => x)\n .otherwise(() => [])\n .includes('https')\n\n const isForwardedSSL = match(req.headers['X-Forwarded-SSL'])\n .with('on', () => true)\n .otherwise(() => false)\n\n const proto = isForwardedProtoHttps || isForwardedSSL ? 'https' : 'http'\n\n return new URL(`${proto}://${req.headers.host}${req.url}`)\n}\n\nexport default async function proxyPreviewMode(\n request: NextRequest,\n context: Context,\n { apiKey }: { apiKey: string },\n): Promise<NextResponse<ProxyPreviewModeResponse>>\nexport default async function proxyPreviewMode(\n req: NextApiRequest,\n res: NextApiResponse<ProxyPreviewModeResponse>,\n { apiKey }: { apiKey: string },\n): Promise<void>\nexport default async function proxyPreviewMode(\n ...args: ProxyPreviewModeHandlerArgs\n): Promise<NextResponse<ProxyPreviewModeResponse> | void> {\n return match(args)\n .with(routeHandlerPattern, args => proxyPreviewModeRouteHandler(...args))\n .with(apiRoutePattern, args => proxyPreviewModeApiRouteHandler(...args))\n .exhaustive()\n}\n\nasync function proxyPreviewModeRouteHandler(\n _request: NextRequest,\n _context: Context,\n {}: { apiKey: string },\n): Promise<NextResponse<ProxyPreviewModeResponse>> {\n const message =\n 'Cannot request preview endpoint from an API handler registered in `app`. Move your Makeswift API handler to the `pages/api` directory'\n console.error(message)\n return NextResponse.json(message, { status: 500 })\n}\n\nasync function proxyPreviewModeApiRouteHandler(\n req: NextApiRequest,\n res: NextApiResponse<ProxyPreviewModeResponse>,\n { apiKey }: { apiKey: string },\n): Promise<void> {\n if (req.query.secret !== apiKey) return res.status(401).send('Unauthorized')\n if (req.headers.host == null) return res.status(400).send('Bad Request')\n\n // TODO: This is a hack to get the locale from the request.\n // Next.js strips the locale from the req.url, and there's no official way to get the locale\n // from an API route: https://github.com/vercel/next.js/discussions/21798.\n // The current workaround is to get the locale from an internal object: RequestMeta,\n // https://github.com/vercel/next.js/blob/a0d1d728b9003f12c9df6c5e9a33bc4c33cef0ab/packages/next/src/server/request-meta.ts\n // One possible way to properly fix this is by updating how we do preview mode. For example,\n // by using partitioned cookies instead of a proxy.\n const NextRequestMetaSymbol = Reflect.ownKeys(req).find(\n key =>\n key.toString() === 'Symbol(NextRequestMeta)' ||\n key.toString() === 'Symbol(NextInternalRequestMeta)',\n ) as keyof NextApiRequest | undefined\n\n if (NextRequestMetaSymbol) {\n const nextRequestMeta = req[NextRequestMetaSymbol]\n const initUrl = nextRequestMeta?.__NEXT_INIT_URL ?? nextRequestMeta?.initURL\n const isLocaleStripped =\n nextRequestMeta?.__nextStrippedLocale ?? nextRequestMeta?.didStripLocale\n\n try {\n if (isLocaleStripped && initUrl) req.url = new URL(initUrl).pathname\n } catch {}\n }\n\n const proxyHeaders = mapRequestHeadersToHeaders(req.headers)\n const proxyUrl = mapRequestToProxyUrl(req)\n\n proxyUrl.searchParams.delete('x-makeswift-preview-mode')\n proxyHeaders.delete('x-makeswift-preview-mode')\n // The following headers are Next.js-specific and are removed to prevent Next.js from\n // short-circuiting requests, breaking routing.\n proxyHeaders.delete('x-invoke-path')\n proxyHeaders.delete('x-invoke-query')\n\n const previewData: MakeswiftPreviewData = {\n makeswift: true,\n // This will eventually be dynamic\n siteVersion: MakeswiftSiteVersion.Working,\n }\n\n const setCookie = res.setPreviewData(previewData).getHeader('set-cookie')\n res.removeHeader('set-cookie')\n\n if (!Array.isArray(setCookie)) return res.status(500).send('Internal Server Error')\n\n setCookie.forEach((cookie) => proxyHeaders.append('cookie', cookie))\n\n const response = await fetch(proxyUrl, {\n headers: proxyHeaders,\n });\n\n response.headers.forEach((value, name) => {\n res.setHeader(name, value);\n })\n\n res.statusCode = response.status;\n res.statusMessage = response.statusText\n\n // `fetch` automatically decompresses the response, but the response headers will keep the\n // `content-encoding` and `content-length` headers. This will cause decoding issues if the client\n // attempts to decompress the response again. To prevent this, we remove these headers.\n //\n // See https://github.com/nodejs/undici/issues/2514.\n if (res.hasHeader('content-encoding')) {\n res.removeHeader('content-encoding')\n res.removeHeader('content-length')\n }\n\n const arrayBuffer = await response.arrayBuffer()\n\n res.write(new Uint8Array(arrayBuffer))\n res.end()\n}\n"],"mappings":"AACA,SAA+B,4BAA4B;AAC3D,SAAsB,oBAAoB;AAC1C,SAAS,GAAG,aAAa;AAkBzB,MAAM,sBAAsB,CAAC,EAAE,WAAW,OAAO,GAAG,EAAE,KAAK,EAAE,GAAG;AAChE,MAAM,kBAAkB,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG;AAE5C,SAAS,2BAA2B,gBAAoD;AACtF,QAAM,UAAU,IAAI,QAAQ;AAE5B,SAAO,QAAQ,cAAc,EAAE,QAAQ,CAAC,CAAC,KAAK,KAAK,MAAM;AACvD,UAAM,KAAK,EACR,KAAK,EAAE,MAAM,EAAE,MAAM,GAAG,CAAAA,WAASA,OAAM,IAAI,SAAO,QAAQ,OAAO,KAAK,GAAG,CAAC,CAAC,EAC3E,KAAK,EAAE,QAAQ,CAAAA,WAAS,QAAQ,IAAI,KAAKA,MAAK,CAAC;AAAA,EACpD,CAAC;AAED,SAAO;AACT;AAEA,SAAS,qBAAqB,KAA0B;AACtD,QAAM,wBAAwB,MAAM,IAAI,QAAQ,mBAAmB,CAAC,EACjE,KAAK,EAAE,QAAQ,OAAK,EAAE,MAAM,GAAG,CAAC,EAChC,KAAK,EAAE,MAAM,EAAE,MAAM,GAAG,OAAK,CAAC,EAC9B,UAAU,MAAM,CAAC,CAAC,EAClB,SAAS,OAAO;AAEnB,QAAM,iBAAiB,MAAM,IAAI,QAAQ,iBAAiB,CAAC,EACxD,KAA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