mirror of
https://github.com/FranP-code/create-better-t-stack.git
synced 2025-10-12 23:52:15 +00:00
cli: update deps
This commit is contained in:
33
apps/web/.open-next/cloudflare/skew-protection.js
Normal file
33
apps/web/.open-next/cloudflare/skew-protection.js
Normal file
@@ -0,0 +1,33 @@
|
||||
import process from "node:process";
|
||||
const DEPLOYMENT_MAPPING_ENV_NAME = "CF_DEPLOYMENT_MAPPING";
|
||||
const CURRENT_VERSION_ID = "current";
|
||||
function maybeGetSkewProtectionResponse(request) {
|
||||
if (false) {
|
||||
const url = new URL(request.url);
|
||||
if (url.hostname === "localhost" || url.hostname.endsWith(".workers.dev")) {
|
||||
return void 0;
|
||||
}
|
||||
const requestDeploymentId = request.headers.get("x-deployment-id") ?? url.searchParams.get("dpl");
|
||||
if (!requestDeploymentId || requestDeploymentId === process.env.DEPLOYMENT_ID) {
|
||||
return void 0;
|
||||
}
|
||||
const mapping = process.env[DEPLOYMENT_MAPPING_ENV_NAME] ? JSON.parse(process.env[DEPLOYMENT_MAPPING_ENV_NAME]) : {};
|
||||
if (!(requestDeploymentId in mapping)) {
|
||||
return void 0;
|
||||
}
|
||||
const version = mapping[requestDeploymentId];
|
||||
if (!version || version === CURRENT_VERSION_ID) {
|
||||
return void 0;
|
||||
}
|
||||
const versionDomain = version.split("-")[0];
|
||||
const hostname = `${versionDomain}-${process.env.CF_WORKER_NAME}.${process.env.CF_PREVIEW_DOMAIN}.workers.dev`;
|
||||
url.hostname = hostname;
|
||||
const requestToOlderDeployment = new Request(url, request);
|
||||
return fetch(requestToOlderDeployment);
|
||||
}
|
||||
}
|
||||
export {
|
||||
CURRENT_VERSION_ID,
|
||||
DEPLOYMENT_MAPPING_ENV_NAME,
|
||||
maybeGetSkewProtectionResponse
|
||||
};
|
||||
Reference in New Issue
Block a user