diff --git a/apps/scandic-web/netlify.toml b/apps/scandic-web/netlify.toml index 0d9ac94a2..7bd58da97 100644 --- a/apps/scandic-web/netlify.toml +++ b/apps/scandic-web/netlify.toml @@ -34,9 +34,6 @@ remote_images = [ "https://imagevault.scandichotels.com.*", ] -[functions."sitemap"] -schedule = "@daily" - [[headers]] for = "/_next/static/*" [headers.values] diff --git a/apps/scandic-web/netlify/functions/sitemap/index.mts b/apps/scandic-web/netlify/functions/sitemap.mts similarity index 56% rename from apps/scandic-web/netlify/functions/sitemap/index.mts rename to apps/scandic-web/netlify/functions/sitemap.mts index 41cc4db4c..ba0ae2b4a 100644 --- a/apps/scandic-web/netlify/functions/sitemap/index.mts +++ b/apps/scandic-web/netlify/functions/sitemap.mts @@ -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", }