JSON response for dynamic page based on Accept header #27102
-
Hi! I'm trying out Nuxt for the first time (after using Vue.js for years) for a project that, in addition to the Vue.js front-end, also needs a (fairly simple) back-end. What I'm trying to achieve is the following: I have a dynamic page What would the right approach be for this in Nuxt? I've tried to find it in the docs, but the only way I was able to got it working was through a middleware that DOES return something (contrary to the note in the docs that says "Middleware handlers should not return anything"). E.g. with a middleware like this: export default defineEventHandler((event) => {
if (!event.headers.get("accept")?.startsWith("text/html")) {
return { test: "blubb" }
}
}) But if middleware handlers should not return anything, how are you supposed to achieve something like this? Any pointers would be really appreciated! Thanks a lot! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
You don't need a middleware for that, right? Setting that up in |
Beta Was this translation helpful? Give feedback.
Linking #25885 + opened #27105, let's follow along there!