Merged in fix/netlify-function-sitemap (pull request #1536)

fix: sitemap netlify function now running

* fix: sitemap netlify function now running

* Merge branch 'master' into fix/netlify-function-sitemap


Approved-by: Bianca Widstam
This commit is contained in:
Linus Flood
2025-03-14 08:51:48 +00:00
parent dabfe0424b
commit 8ca862e32c
2 changed files with 13 additions and 8 deletions

View File

@@ -34,9 +34,6 @@ remote_images = [
"https://imagevault.scandichotels.com.*",
]
[functions."sitemap"]
schedule = "@daily"
[[headers]]
for = "/_next/static/*"
[headers.values]

View File

@@ -1,7 +1,7 @@
/* eslint-disable import/no-anonymous-default-export */
import type { Context } from "@netlify/functions"
import type { Config, Context } from "@netlify/functions"
export default async (request: Request, context: Context) => {
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")
@@ -11,7 +11,15 @@ export default async (request: Request, context: Context) => {
const headers = new Headers()
headers.set("x-sitemap-sync-secret", SITEMAP_SYNC_SECRET!)
fetch(`${PUBLIC_URL}/api/sitemap`, {
headers,
})
try {
await fetch(`${PUBLIC_URL}/api/sitemap`, {
headers,
})
} catch (error) {
console.error(`Error syncing sitemap: ${error}`)
}
}
export const config: Config = {
schedule: "@daily",
}