express-subdomain-handler icon indicating copy to clipboard operation
express-subdomain-handler copied to clipboard

Cannot GET / error (express 3.0)

Open asmcad opened this issue 11 years ago • 4 comments

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?

asmcad avatar Jan 02 '14 06:01 asmcad

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

wilsonpage avatar Jan 02 '14 11:01 wilsonpage

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?

asmcad avatar Jan 02 '14 12:01 asmcad

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.

wilsonpage avatar Jan 02 '14 18:01 wilsonpage

I am using Express 3.0. I'll debug it an see what happens. Thanks.

asmcad avatar Jan 03 '14 06:01 asmcad