Skip to content

Commit 33598c8

Browse files
committedJul 26, 2024·
fix: fallback to prerender sitemap on vercel edge
Relates to #256
1 parent eddba65 commit 33598c8

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed
 

‎src/module.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,6 @@ declare module 'vue-router' {
722722
handler: resolve('./runtime/nitro/routes/sitemap.xml'),
723723
})
724724

725-
setupPrerenderHandler(runtimeConfig)
725+
setupPrerenderHandler({ runtimeConfig, logger })
726726
},
727727
})

‎src/prerender.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import chalk from 'chalk'
99
import { dirname } from 'pathe'
1010
import { build } from 'nitropack'
1111
import { defu } from 'defu'
12+
import type { ConsolaInstance } from 'consola'
1213
import { extractSitemapMetaFromHtml } from './util/extractSitemapMetaFromHtml'
1314
import type { ModuleRuntimeConfig, SitemapUrl } from './runtime/types'
1415
import { splitForLocales } from './runtime/utils-pure'
@@ -43,9 +44,14 @@ export function isNuxtGenerate(nuxt: Nuxt = useNuxt()) {
4344
].includes(resolveNitroPreset())
4445
}
4546

46-
export function setupPrerenderHandler(options: ModuleRuntimeConfig, nuxt: Nuxt = useNuxt()) {
47+
export function setupPrerenderHandler(_options: { runtimeConfig: ModuleRuntimeConfig, logger: ConsolaInstance }, nuxt: Nuxt = useNuxt()) {
48+
const { runtimeConfig: options, logger } = _options
4749
const prerenderedRoutes = (nuxt.options.nitro.prerender?.routes || []) as string[]
48-
const prerenderSitemap = isNuxtGenerate() || includesSitemapRoot(options.sitemapName, prerenderedRoutes)
50+
let prerenderSitemap = isNuxtGenerate() || includesSitemapRoot(options.sitemapName, prerenderedRoutes)
51+
if (resolveNitroPreset() === 'vercel-edge') {
52+
logger.warn('Runtime sitemaps are not supported on Vercel Edge, falling back to prerendering sitemaps.')
53+
prerenderSitemap = true
54+
}
4955
// need to filter it out of the config as we render it after all other routes
5056
if (nuxt.options.nitro.prerender?.routes)
5157
nuxt.options.nitro.prerender.routes = nuxt.options.nitro.prerender.routes.filter(r => r && !includesSitemapRoot(options.sitemapName, [r]))

0 commit comments

Comments
 (0)
Please sign in to comment.