Skip to content

Commit

Permalink
fix: vercel do not support __ prefix for api route
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <[email protected]>
  • Loading branch information
Innei committed Nov 7, 2024
1 parent 2f8dc0b commit 45a66e0
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions api/__webhook.ts → api/vercel_webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ export default async function handler(request: VercelRequest, response: VercelRe
const { WEBHOOK_SECRET: INTEGRATION_SECRET } = process.env

if (typeof INTEGRATION_SECRET != "string") {
throw new TypeError("No integration secret found")
return response.status(400).json({
code: "invalid_secret",
error: "No integration secret found",
})
}

const rawBody = await getRawBody(request)
Expand All @@ -28,7 +31,7 @@ export default async function handler(request: VercelRequest, response: VercelRe
const { target } = json.payload || json.data

if (target === "production") {
purgeCloudflareCache()
return purgeCloudflareCache(response)
}
}
// ...
Expand All @@ -47,11 +50,14 @@ export const config = {
},
}

async function purgeCloudflareCache() {
async function purgeCloudflareCache(response: VercelResponse) {
const { CF_TOKEN, CF_ZONE_ID } = process.env

if (typeof CF_TOKEN !== "string" || typeof CF_ZONE_ID !== "string") {
throw new TypeError("No Cloudflare token or zone ID found")
return response.status(400).json({
code: "invalid_secret",
error: "No Cloudflare token or zone ID found",
})
}

const apiUrl = `https://api.cloudflare.com/client/v4/zones/${CF_ZONE_ID}/purge_cache`
Expand Down

0 comments on commit 45a66e0

Please sign in to comment.