N
Nuxt9mo ago
Ziko

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?
3 Replies
Ziko
ZikoOP9mo ago
More info: The error i get while trying to useRequestUrl, is: 'Vue app aliases are not allowed in server runtime.'
numbani
numbani9mo ago
do you mean the params?
export default defineEventHandler(async (event) => {
const user =event.context.sessions?event.context.sessions.user.id: event.context.params?.user
const service = event.context.params?.service
if (!user) {
throw new Error("User not found")
}
if (!service) {
throw new Error("Service not found")
}
console.log("user:",user)
console.log("service:",service)
export default defineEventHandler(async (event) => {
const user =event.context.sessions?event.context.sessions.user.id: event.context.params?.user
const service = event.context.params?.service
if (!user) {
throw new Error("User not found")
}
if (!service) {
throw new Error("Service not found")
}
console.log("user:",user)
console.log("service:",service)
Ziko
ZikoOP9mo ago
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 Is it not possible to set some context on the event.context in the eventHandler ? I see this as the least worse idea ATM Just seems like something that should be easily done 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
Want results from more Discord servers?
Add your server