chore: Migrate from next lint to eslint * Migrate scandic-web * Migrate partner-sas * Enable any rule in partner-sas Approved-by: Joakim Jäderberg Approved-by: Linus Flood
41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
/* eslint-disable no-console */
|
|
/* 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 {
|
|
const url = new URL(
|
|
"/api/web/sitemap",
|
|
PUBLIC_URL || "https://www.scandichotels.com"
|
|
)
|
|
const response = await fetch(url, {
|
|
headers,
|
|
signal: AbortSignal.timeout(30_000),
|
|
})
|
|
if (!response.ok) {
|
|
const text = await response.text()
|
|
throw new Error(
|
|
`HTTP error syncing sitemap! status: ${response.status}, url: ${url.href}, message: ${text}`
|
|
)
|
|
}
|
|
} catch (error) {
|
|
console.error(`Error syncing sitemap: ${error}`)
|
|
return new Response("Failed to sync sitemap", { status: 500 })
|
|
}
|
|
console.log(`Sitemap synced initiated successfully`)
|
|
return new Response("Sitemap synced successfully", { status: 200 })
|
|
}
|
|
|
|
export const config: Config = {
|
|
schedule: "0 2/12 * * *", // every 12 hours, start at 02.00
|
|
}
|