site: fix dev-server 404 on scoped feed URLs
With trailingSlash 'always', astro dev only matches dynamic-route endpoints when the request has a trailing slash, so the RSS pill links (/tags/<t>/rss.xml, /categories/<c>/rss.xml) 404'd locally while the built site served them fine. Dev-only vite middleware rewrites those requests to the slashed form. Claude-Session: https://claude.ai/code/session_01WZaczDJjL3xZ3u5spsN5AL
This commit is contained in:
+16
-1
@@ -128,11 +128,26 @@ const setPickApi = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// With trailingSlash 'always', the dev server only matches dynamic-route
|
||||||
|
// endpoints (/tags/<t>/rss.xml, /categories/<c>/rss.xml) when the request
|
||||||
|
// has a trailing slash; the built site serves them as plain files without
|
||||||
|
// one. Rewrite in dev so the same URLs work in both.
|
||||||
|
const feedSlashShim = {
|
||||||
|
name: 'feed-trailing-slash-dev-shim',
|
||||||
|
apply: 'serve',
|
||||||
|
configureServer(server) {
|
||||||
|
server.middlewares.use((req, res, next) => {
|
||||||
|
if (/^\/(tags|categories)\/[^/]+\/rss\.xml$/.test(req.url)) req.url += '/';
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
site: 'https://unique.rzen.dev',
|
site: 'https://unique.rzen.dev',
|
||||||
trailingSlash: 'always',
|
trailingSlash: 'always',
|
||||||
build: { format: 'directory' },
|
build: { format: 'directory' },
|
||||||
vite: { plugins: [editFindTagApi, setPickApi] },
|
vite: { plugins: [editFindTagApi, setPickApi, feedSlashShim] },
|
||||||
integrations: [
|
integrations: [
|
||||||
mdx(),
|
mdx(),
|
||||||
sitemap({
|
sitemap({
|
||||||
|
|||||||
Reference in New Issue
Block a user