You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Based on the docs /api is just a convenient way to create routes and automatically prefix them with /api - https://nitro.unjs.io/guide#api.
This PR partially fixes the problem by allowing to rename the route prefix #1763
But some projects may want to have multiple "api" endpoints (f.e. /api, /cms, /commerce etc), so they should have possibility to response with JSON when throwing errors.
@pi0 Is it intentional that /routes returns an html page and /api a json response? If yes, can this be unified so both act the same? And at the same time add a config option to nitro.config.ts to enable/disable html responses?
Personally I dont want the /api prefix but also I dont want any html responses in my rest api at all.
Environment
Operating System: Linux
Node Version: v18.18.0
CLI Version: 3.10.1
Nitro Version: 2.9.1
Package Manager: [email protected]
Reproduction
https://stackblitz.com/edit/github-zyt6se?file=routes%2Ffoo.ts,api%2Ffoo.ts,public%2Findex.html
Describe the bug
Check the response for
/api/foo
and/foo
endpoints. Each of them throws same 404 error in the handler, but:/foo
-> returns error as html page/api/foo
-> returns error as json object as expectedAdditional context
No response
Logs
No response
The text was updated successfully, but these errors were encountered: