express-subdomain-handler
express-subdomain-handler copied to clipboard
Cannot GET / error (express 3.0)
app.use( require('express-subdomain-handler')({ baseUrl: 'node.localhost', prefix: 'subdomain', logger: true }) );
app.get('/subdomain/mysubdomain/',some.somert)
mysubdomain.node.localhost:1337 or mysubdomain.localhost:1337
doesn'T work either. what am i doing wrong?
is it something with the version of expressjs?
When you say "doesn't work" it's hard to diagnose the problem. The localhost domain will not accept 'wildcard' subdomains by default. You will have to add each full host to your /etc/hosts file, some thing like:
127.0.0.1 mysubdomain.node.localhost
127.0.0.1 mysubdomain.localhost
Thanks for quick reply and sorry for not detailed explanation but there was not much code. It is just standard expressjs project.
app.use( require('express-subdomain-handler')({ baseUrl: 'localhost', prefix: 'subdomain', logger: true}) );
app.get('/subdomain/:mysubdomain/thepage', function(req, res, next){ res.send("some text"); console.log(req.params.mysubdomain); });
and my host file:
127.0.0.1 mysubdomain.node.localhost 127.0.0.1 mysubdomain.localhost
When i try this page : http://mysubdomain.localhost:1337/thepage
I get : Cannot GET /thepage
Is there something wrong here that i don't see?
What version of Express are you using? I wrote this a long time ago for Express 2.0. I have not tried it in Express 3.0. I'm afraid I don't have the time to look into this further, but I would recommend throwing some console.log() statements around to try to identify the problem.
I am using Express 3.0. I'll debug it an see what happens. Thanks.