feat: add support for redirecting to md if accept text/markdown#2160
feat: add support for redirecting to md if accept text/markdown#2160
Conversation
Co-Authored-By: Pooya Parsa <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Deployment failed with the following error: |
Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Additional Suggestion:
The route parameter is accessed with an incorrect key name. The parameter should be slug (from the [...slug] dynamic segment), not slug.md.
View Details
📝 Patch Details
diff --git a/server/routes/raw/[...slug].md.get.ts b/server/routes/raw/[...slug].md.get.ts
index 285d4564..2cd7be80 100644
--- a/server/routes/raw/[...slug].md.get.ts
+++ b/server/routes/raw/[...slug].md.get.ts
@@ -3,7 +3,7 @@ import { stringify } from 'minimark/stringify'
import { withLeadingSlash } from 'ufo'
export default eventHandler(async (event) => {
- const slug = getRouterParams(event)['slug.md']
+ const slug = getRouterParams(event)['slug']
if (!slug?.endsWith('.md')) {
throw createError({ statusCode: 404, statusMessage: 'Page not found', fatal: true })
}
Analysis
Incorrect route parameter key in raw markdown route handler
What fails: Line 6 of server/routes/raw/[...slug].md.get.ts accesses getRouterParams(event)['slug.md'], which returns undefined for all requests, causing every request to /raw/...md to fail with a 404 error.
How to reproduce: Make any GET request to a markdown route:
curl http://localhost:3000/raw/docs/guide.mdResult: Returns 404 "Page not found" because slug parameter is undefined, causing the check !slug?.endsWith('.md') to evaluate to true.
Expected: The request should succeed and return the markdown file content, with the slug parameter properly populated.
Root cause: In Nuxt/Nitro server routes with dynamic segments, the parameter name comes ONLY from the content inside brackets. For a filename [...slug].md.get.ts:
- The
[...slug]creates a parameter namedslug - The
.mdextension and.getHTTP method suffix are NOT part of the parameter name - This is confirmed by the similar file
server/api/v1/teams/[slug].get.tswhich usesgetRouterParam(event, 'slug')- notgetRouterParam(event, 'slug.get')
Nitro routing documentation confirms: "You can append the HTTP method to the filename to force the route to be matched only for a specific HTTP request method... the param will be available in the event.context.params object using the bracket notation name only."
Fix: Change line 6 from const slug = getRouterParams(event)['slug.md'] to const slug = getRouterParams(event)['slug']
So AI crawler can directly access Markdown content for our docs