Merged in feature/hardcode-release-branch-warming (pull request #2052)

fix: hardcode release branch warmup

* fix: hardcode release branch warmup

* .


Approved-by: Anton Gunnarsson
This commit is contained in:
Joakim Jäderberg
2025-05-13 13:19:09 +00:00
parent ccaf705015
commit a71ccbdf22

View File

@@ -19,7 +19,7 @@ async function WarmupHandler(request: Request, context: Context) {
case ErrorCodes.WARMUP_DISABLED:
console.warn("[WARMUP] Warmup is disabled")
return
case ErrorCodes.URLS_DONT_MATCH:
case ErrorCodes.REQUEST_NOT_FOR_CURRENT_CONTEXT:
// This is expected, this webhook will be called for all deployments
// and we only want to warmup the ones that match our URL
return
@@ -63,9 +63,13 @@ async function validateRequest(
throw new Error(ErrorCodes.UNABLE_TO_PARSE_DEPLOYMENT_INFO)
}
const deployedUrl = deployment.deploy_ssl_url
if (deployedUrl !== context.url.origin) {
throw new Error(ErrorCodes.URLS_DONT_MATCH)
const isForCurrentContext = isRequestForCurrentContext({
currentUrl: context.url.origin,
deployedUrl: deployment.deploy_ssl_url,
})
if (!isForCurrentContext) {
throw new Error(ErrorCodes.REQUEST_NOT_FOR_CURRENT_CONTEXT)
}
console.log("[WARMUP] Warmup request", deployment)
@@ -177,6 +181,20 @@ function hasSha256(decoded: unknown): decoded is { sha256: string } {
)
}
function isRequestForCurrentContext({
currentUrl,
deployedUrl,
}: {
currentUrl: string
deployedUrl: string
}) {
const isForProduction =
currentUrl === "https://web-scandic-hotels.netlify.app" &&
deployedUrl === "https://release--web-scandic-hotels.netlify.app"
return isForProduction || currentUrl === deployedUrl
}
type DeploymentInfo = {
id: string
site_id: string
@@ -243,7 +261,7 @@ const ErrorCodes = {
MISSING_SIGNATURE_HEADER: "MISSING SIGNATURE HEADER",
MISSING_SIGNATURE: "MISSING SIGNATURE",
UNABLE_TO_PARSE_DEPLOYMENT_INFO: "UNABLE TO PARSE DEPLOYMENT INFO",
URLS_DONT_MATCH: "URLS DONT MATCH",
REQUEST_NOT_FOR_CURRENT_CONTEXT: "REQUEST NOT FOR CURRENT CONTEXT",
WARMUP_DISABLED: "WARMUP IS DISABLED",
} as const
type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes]