feat(sitemap): change scheduled time * feat(sitemap): change scheduled time Approved-by: Erik Tiekstra
29 lines
940 B
TypeScript
29 lines
940 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: "0 2/12 * * *", // every 12 hours, start at 02.00
|
|
}
|