Files
web/apps/scandic-web/netlify/functions/sitemap.mts
Linus Flood bed490d79a Merged in fix/sitemap-function (pull request #1654)
feat(sitemap): change scheduled time

* feat(sitemap): change scheduled time


Approved-by: Erik Tiekstra
2025-03-27 12:31:28 +00:00

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
}