node.js, trying to route sub-domain to specific directory

189 views Asked by At

I'm currently using bouncy to route specific sub-domains to node projects running on different ports like so

var bouncy = require('bouncy');

var server = bouncy(function (req, res, bounce) {
    switch(req.headers.host){
        case "first.domain.com" : bounce(3000); break;
        case "second.domain.com" : bounce(3001); break;
    }
});
server.listen(80);

that works fine, but I also want to be able to resolve particular sub-domain's to specific directories like so

        case "third.domain.com" : bounce(3001+"/folder"); break;

Obviously that doesn't work, but in theory that's what I'm trying to do. I've been looking at http-proxy but I can't seem to figure out how to use it in this way either.

I'm new to node ( and rolling out "servers" in general ) It's my understanding that I could use ngnix to accomplish this but I was hoping to keep things simple by resolving this within the node server code.

1

There are 1 answers

2
Patosai On

Try

case "third.domain.com" : bounce(3001, { path: '/folder' }); break;