javascript - Specifying routes by subdomain in Express using vhost middleware -


i'm using vhost express/connect middleware , i'm bit confused how should used. want have 1 set of routes apply hosts subdomains, , set apply hosts without subdomains.

in app.js file, have

var app = express.createserver();  app.use...(middlware)... app.use(express.vhost('*.host', require('./domain_routing')("yes"))); app.use(express.vhost('host', require('./domain_routing')("no"))); app.use...(middlware)...  app.listen(8000); 

and in domain_routing.js:

module.exports = function(subdomain){    var app = express.createserver();    require('./routes')(app, subdomain);    return app; } 

and in routes.js plan run sets of routes, dependent on whether subdomain variable passed in "yes" or "no".

am on right track or not how use middleware? i'm bit confused on fact there 2 app server instances being created (as that's how examples on web seem things). should instead pass in original app server instance , use instead of creating separate 1 instead subdomain router?

yes, on right track. should have different server instance each of vhost. http.server or express app.

if pass original app, request sent vhost emitted original app. so, unless vhost has paths not used in original server, response if request sent original server.

from connect docs

connect()   .use(connect.vhost('foo.com', fooapp))   .use(connect.vhost('bar.com', barapp))   .use(connect.vhost('*.com', mainapp)) 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -