Feat/warmup cache function * WIP * Fix warmup for all languages * Cleanup * Added env flag so we can disable warmup * Changed time to 04.00 UTC since backend updates their data at 03.00 UTC * Add return statements * Merge branch 'master' into feat/warmup-cache-function Approved-by: Anton Gunnarsson
29 lines
900 B
TypeScript
29 lines
900 B
TypeScript
/* eslint-disable import/no-anonymous-default-export */
|
|
import type { Config, Context } from "@netlify/functions"
|
|
|
|
export default async (request: Request, _context: Context) => {
|
|
const { next_run } = await request.json()
|
|
const SITEMAP_SYNC_SECRET = Netlify.env.get("SITEMAP_SYNC_SECRET")
|
|
const PUBLIC_URL = Netlify.env.get("PUBLIC_URL")
|
|
console.info(
|
|
`Started sitemap sync at: ${new Date().toISOString()}! Next invocation at: ${next_run}`
|
|
)
|
|
const headers = new Headers()
|
|
headers.set("x-sitemap-sync-secret", SITEMAP_SYNC_SECRET!)
|
|
|
|
try {
|
|
await fetch(`${PUBLIC_URL}/api/sitemap`, {
|
|
headers,
|
|
})
|
|
} catch (error) {
|
|
console.error(`Error syncing sitemap: ${error}`)
|
|
return new Response("Failed to sync sitemap", { status: 500 })
|
|
}
|
|
|
|
return new Response("Sitemap synced successfully", { status: 200 })
|
|
}
|
|
|
|
export const config: Config = {
|
|
schedule: "@daily",
|
|
}
|