Combine multiple node.js web applications

后端 未结 1 1830
北荒
北荒 2021-02-10 12:19

I\'m trying to figure out the best way to accomplish this; essentially I have about 6 websites I have to get online but at the moment they will have next to zero traffic so to s

相关标签:
1条回答
  • 2021-02-10 12:42

    Use connect vhost. http://www.senchalabs.org/connect/vhost.html

    var express = require('express'),
        main = express();
    
    main.use(express.vhost('*.site1.com', require('../site1')));
    main.use(express.vhost('*.site2.com', require('../site2')));
    
    main.listen(80);
    

    And ../site1/index.js might look like this:

    var express = require('express'),
        app = express();
    
    app.get('/', function(req, res) { res.send('Home Page'); });
    
    module.exports = app;
    
    0 讨论(0)
提交回复
热议问题