Merged in fix/sitemap-issue (pull request #1788)
fix/sitemap: default to prod url and added logging. Also added new sitemap function to be able to invoke it on request. * test * wip * wip * Added error message to log Approved-by: Joakim Jäderberg
This commit is contained in:
@@ -12,14 +12,24 @@ export default async (request: Request, _context: Context) => {
|
||||
headers.set("x-sitemap-sync-secret", SITEMAP_SYNC_SECRET!)
|
||||
|
||||
try {
|
||||
await fetch(`${PUBLIC_URL}/api/sitemap`, {
|
||||
const url = new URL(
|
||||
"/api/sitemap",
|
||||
PUBLIC_URL || "https://www.scandichotels.com"
|
||||
)
|
||||
const response = await fetch(url, {
|
||||
headers,
|
||||
})
|
||||
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 })
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user