req.vhost is undefined
See original GitHub issueThis is my main code, but I get req.vhost is undefined, any idea what can cause it?
app.use(function(req, res, next){
console.log(req.vhost)
var username = req.vhost[0] // username is the "*"
console.log(username)
// pretend request was for /{username}/* for file serving
req.originalUrl = req.url;
console.log('req '+ req.originalUrl)
req.url = '/' + username + req.url
console.log(req.url)
next()
})
app.use(vhost('*.myapp.local', indexRouter))
if I delete the console logs in the middleware the right route is rendered, but it is important to have access to the req.vhost[0] to render dynamic data based on the subdomain the user is typing
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
node.js - VHost in ExpressJS accessing pages of main website
Suppose you have a contact page in the main domain, you can make changes like. sub.get('/contact', function(req, res){ return res.
Read more >@tryghost/vhost-middleware - npm
When host is matched and the request is sent down to a vhost handler, the req.vhost property will be populated with an object....
Read more >"Virtual Host/WebGroup not Found" Error When Submitting ...
This problem is usually related to an incorrect configuration of a virtual host, or a necessary component that has not been started. Resolving ......
Read more >Apache Default/Catch-All Virtual Host? - Server Fault
A default vhost never serves a request that was sent to an address/port that is used for name-based vhosts. If the request contained...
Read more >An In-Depth Discussion of Virtual Host Matching ... - setgetweb.com
In other words the main_server only catches a request for an unspecified address/port combination (unless there is a _default_ vhost which matches that...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @mrrovot , the
req.vhost
property is not populated until the request actually passes though this middleware. In your example, you are accessingreq.vhost
before this middleware is ever invoked. In addition, thereq.vhost
property is only available within the defined handler, which in your case is theindexRouter
.I hope that helps.
the
req.vhost[0]
is commented out, I meant where there isconsole.log(req.vhost)
I couldn’t access the[0]
but as I was recreating a simple app with the error to send you, it now it works!, probably it was something I mistyped last nightthanks for the help