nitro
nitro copied to clipboard
getRequestURL in a server plugin, middleware, etc. does not consistently return the actual origin or hostname of the deployed site/worker
Environment
- Nitro
2.9.6
- Nuxt
3.11.2
Reproduction
Description | URL |
---|---|
Deploy preview | https://nitro_origin_repro.adamdehaven.workers.dev/ |
CodeSandbox | https://codesandbox.io/p/github/adamdehaven/nitro-origin-repro/main |
Code | https://github.com/adamdehaven/nitro-origin-repro |
Describe the bug
When utilizing getRequestURL(event)
inside Nitro middleware (or inside a Nitro plugin, etc.) in a Nuxt project, I would expect the origin
and hostname
to return the deployed hostname and origin of the request rather than an "internal" server origin/host or something hidden behind a CNAME.
Additional context
I utilized a Nuxt app as a reproduction. You should be able to see where I am attempting to retrieve and store the origin and hostname via getRequestURL
in /server/middleware/set-origin.ts
I'm fully aware I could be missing something obvious or intended, so if this is the case, I'd greatly appreciate some help in understanding what's going on and what is to be expected based on the code in the reproduction.
Problem I'm trying to solve (simplified):
I have a Nuxt application that will be serving a multi-tenant application whereby the Nuxt layers provide all functionality, and content is loaded at runtime per tenant.
We will be utilizing dynamic subdomains to determine which tenant's app is being requested, so I'd expect to be able to utilize any request event
to identify app1.example.com
or app2.example.com
based on the origin
or hostname
extracted via getRequestURL(event)
.
Logs
No response