How to get full req URL in server plugin & update appConfig that gets carried/reflected to client
Hi π
I'm building nuxt template and encoutering strange case where I want to deploy single nuxt app and want to server it from 6 different URL for different demo purposes.
Question:
How can I get full requested URL in server plugin like
domain.com/demo-1/
(I need subpath ("demo-1") my nuxt is serving to). Based on this requested path I want to alter the appConfig from server plugin and want to reflect that config in client app. e.g. demo-1 will have light theme & demo-2 will have dark theme.
I tried getting full url but nuxtApp.ssrContext?.event.node.req.url
only gives app's route path not requested URL. π€· (something like this: https://nuxt.com/docs/getting-started/testing#urlpath)11 Replies
const host = getRequestHost(e, { xForwardedHost: true })
However neither
getRequestHost
nor getRequestURL
returns the full URL π
I got log when I visit: http://localhost:3000/vuexy-vuejs-admin-template/demo/Just combine them?
Or is base url the nitro base?
base is from nuxt config:
I guess it's h3's bug where it doesn't consider the base URL if we visit: http://localhost:3000/vuexy-vuejs-admin-template/demo/about
Uh ye because the util doesn't have that context
URL is
localhost/about
instead of full pathYou'll need to construct it yourself
Actually, I need to get the full served path like
http://localhost:3000/vuexy-vuejs-admin-template/demo/about
because I have very special case where single nuxt app will get served by six different demos. (I will server demo-1,2,3,4,5,6 urls from single nuxt app and change the app config based on visited demo) using nginx
Meaning demo
in baseUrl is just for single deployment dir, I'm going to server that demo
dir's nuxt to six different sub paths named above π
There may be a nuxt util for this, can't remeber, I've been rolling my own on my modules