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:
@@ -19,7 +19,7 @@ async function WarmupHandler(request: Request, context: Context) {
|
|||||||
case ErrorCodes.WARMUP_DISABLED:
|
case ErrorCodes.WARMUP_DISABLED:
|
||||||
console.warn("[WARMUP] Warmup is disabled")
|
console.warn("[WARMUP] Warmup is disabled")
|
||||||
return
|
return
|
||||||
case ErrorCodes.URLS_DONT_MATCH:
|
case ErrorCodes.REQUEST_NOT_FOR_CURRENT_CONTEXT:
|
||||||
// This is expected, this webhook will be called for all deployments
|
// This is expected, this webhook will be called for all deployments
|
||||||
// and we only want to warmup the ones that match our URL
|
// and we only want to warmup the ones that match our URL
|
||||||
return
|
return
|
||||||
@@ -63,9 +63,13 @@ async function validateRequest(
|
|||||||
throw new Error(ErrorCodes.UNABLE_TO_PARSE_DEPLOYMENT_INFO)
|
throw new Error(ErrorCodes.UNABLE_TO_PARSE_DEPLOYMENT_INFO)
|
||||||
}
|
}
|
||||||
|
|
||||||
const deployedUrl = deployment.deploy_ssl_url
|
const isForCurrentContext = isRequestForCurrentContext({
|
||||||
if (deployedUrl !== context.url.origin) {
|
currentUrl: context.url.origin,
|
||||||
throw new Error(ErrorCodes.URLS_DONT_MATCH)
|
deployedUrl: deployment.deploy_ssl_url,
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!isForCurrentContext) {
|
||||||
|
throw new Error(ErrorCodes.REQUEST_NOT_FOR_CURRENT_CONTEXT)
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("[WARMUP] Warmup request", deployment)
|
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 = {
|
type DeploymentInfo = {
|
||||||
id: string
|
id: string
|
||||||
site_id: string
|
site_id: string
|
||||||
@@ -243,7 +261,7 @@ const ErrorCodes = {
|
|||||||
MISSING_SIGNATURE_HEADER: "MISSING SIGNATURE HEADER",
|
MISSING_SIGNATURE_HEADER: "MISSING SIGNATURE HEADER",
|
||||||
MISSING_SIGNATURE: "MISSING SIGNATURE",
|
MISSING_SIGNATURE: "MISSING SIGNATURE",
|
||||||
UNABLE_TO_PARSE_DEPLOYMENT_INFO: "UNABLE TO PARSE DEPLOYMENT INFO",
|
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",
|
WARMUP_DISABLED: "WARMUP IS DISABLED",
|
||||||
} as const
|
} as const
|
||||||
type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes]
|
type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes]
|
||||||
|
|||||||
Reference in New Issue
Block a user