From c93134975a52a6c66c63f9cfc06c302b3874c74d Mon Sep 17 00:00:00 2001 From: Djeex Date: Tue, 11 Aug 2026 11:44:46 +0200 Subject: [PATCH] feat: generate /fr/sitemap.xml via custom Nitro route MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit @nuxtjs/sitemap is incompatible with app.baseURL: '/fr/' here — it broke nginx routing (403) on this deployment where /fr/ is served via an alias to a separate static build. A hand-rolled Nitro route sidesteps the module entirely and gets prerendered to a plain sitemap.xml file at the root of the generated output, matching what the nginx alias expects. Co-Authored-By: Claude Sonnet 5 --- nuxt.config.ts | 6 ++++++ server/routes/sitemap.xml.ts | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 server/routes/sitemap.xml.ts diff --git a/nuxt.config.ts b/nuxt.config.ts index 24f47c5..76bec46 100755 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -44,5 +44,11 @@ export default defineNuxtConfig({ } }, + nitro: { + prerender: { + routes: ['/sitemap.xml'] + } + }, + compatibilityDate: '2024-10-24' }) \ No newline at end of file diff --git a/server/routes/sitemap.xml.ts b/server/routes/sitemap.xml.ts new file mode 100644 index 0000000..905e31b --- /dev/null +++ b/server/routes/sitemap.xml.ts @@ -0,0 +1,23 @@ +import { serverQueryContent } from '#content/server' + +// generates /fr/sitemap.xml without @nuxtjs/sitemap (incompatible with baseURL /fr/) +export default defineEventHandler(async (event) => { + const docs = await serverQueryContent(event).find() + + const urls = docs + .filter((doc: any) => + doc._path && + !doc._path.startsWith('/_') && + !doc._path.endsWith('/_dir') + ) + .map((doc: any) => ` https://docu.djeex.fr/fr${doc._path}`) + .join('\n') + + const sitemap = ` + +${urls} +` + + setHeader(event, 'Content-Type', 'application/xml') + return sitemap +})