Getting Nuxt page (URL/Name) in API server request?
Hi All
I'm having trouble getting the nuxt component/page full path dynamically in my API eventhandler, without having to pass it as some sort of data in the request.
I've tried checking all the composables, but the one that works for me in middleware doesn't work in the API server:
useRequestURL();
Any ideas?9 Replies
More info: The error i get while trying to
useRequestUrl
, is: 'Vue app aliases are not allowed in server runtime.'do you mean the params?
Let say i have page: pages/abc.vue, that requests nuxt API server: /api/def
In def eventHandler i want to know what page requested the API, but i can at most only get origin: localhost:4200
The href for the event, is also only the api endpoint
I want the page origin URL path
You can't get the origin path through raw http
I would suggest using cookies if you really need the origin path (set current path before sending request)
Is it not possible to set some context on the event.context in the eventHandler ?
I see this as the least worse idea ATM
event.context is server side only, don't think that would work
Just seems like something that should be easily done
I myself actually use query parameters
So you send the current path as a query to the server
Just make sure you deal with security stuff like CSRF
I'm trying to do a pseudo CMS, so i need to validate the page url. Which is why i dont want to do it in query/body