Skip to content

Commit

Permalink
fix: fallback to prerender sitemap on vercel edge
Browse files Browse the repository at this point in the history
Relates to #256
  • Loading branch information
harlan-zw committed Jul 26, 2024
1 parent eddba65 commit 33598c8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,6 @@ declare module 'vue-router' {
handler: resolve('./runtime/nitro/routes/sitemap.xml'),
})

setupPrerenderHandler(runtimeConfig)
setupPrerenderHandler({ runtimeConfig, logger })
},
})
10 changes: 8 additions & 2 deletions src/prerender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import chalk from 'chalk'
import { dirname } from 'pathe'
import { build } from 'nitropack'
import { defu } from 'defu'
import type { ConsolaInstance } from 'consola'
import { extractSitemapMetaFromHtml } from './util/extractSitemapMetaFromHtml'
import type { ModuleRuntimeConfig, SitemapUrl } from './runtime/types'
import { splitForLocales } from './runtime/utils-pure'
Expand Down Expand Up @@ -43,9 +44,14 @@ export function isNuxtGenerate(nuxt: Nuxt = useNuxt()) {
].includes(resolveNitroPreset())
}

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

0 comments on commit 33598c8

Please sign in to comment.