How to handle wildcard subdomain proxy with Nuxt Milddleware properly on both server & client? #33545
Unanswered
maximelebreton
asked this question in
Questions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi π
I have a Nuxt 4 project with user slugs, like:
http://localhost:3000/@alexlitcherAnd a folder structure like:
The app runs in SSR mode.
Iβd like to proxy subdomains to these user pages, for example:
http://alexlitcher.localhost:3000β proxies tohttp://localhost:3000/@alexlitcherSo I created a
server/middleware/subdomain.ts:This works perfectly on the server β
http://alexlitcher.localhost:3000correctly renders thehttp://localhost:3000/@alexlitcherpage.However, when hydration happens on the client, the URL becomes:
If JavaScript is disabled, everything works fine.
But when JS enabled, the redirect append the
/@alexlitcherto the url after hydration.Why does this happen, and whatβs the proper way to handle this kind of subdomain β route mapping in Nuxt 4?
I already tried the
router.options.tsmethod (#16536 (comment)) as mentioned by @TheAlexLichter, but it's not satisfying because it's more difficult to handle cache with Netlify / Vercel / Cloudflare. (especially because you need to set Cache Tags or Vary headers, and each company has his own implementation and limitations, and it's a full nightmare!)Thanks a lot for your helpπ
Beta Was this translation helpful? Give feedback.
All reactions