0

im curious if it's possible to run several Angular2/4 instances with the same port, but different subdomains/domains.

When i try to run one instance on my local ip and one on localhost, the second time i start angular, i get an error that port 4200 is already in use.

As this is the same, as running two instances on one server with different subdomains, it would be a bummer if it wouldn't be possible.

  • Angular runs in a browser, not on a server. Angular applications are served by HTTP servers (Node.js, Apache httpd, nginx). So you want to have multiple applications served by a single HTTP server. – Ján Halaša Aug 21 '17 at 12:45

2 Answers2

0

Maybe this SO question would shed some light:

How do I host multiple Node.js sites on the same IP/server with different domains?

Seems like you can accomplish that with nginx which is what we plan to use to host multiple versions of our node.js/angular app

Justin Morrison
  • 459
  • 4
  • 18
0

Yes it is possible, for that in your app.js or whatever your node entry script check the requested host and parsed the subdomain from it. And on the behalf of that you need serve the angular2 and angular4 app. Here is the example code.

app.use('/',function(req,res,next){
    var subdomain = extractSubDomain(req.headers.host);
    if(subdomain=="subdomain1"){
        app.use(express.static(path.join(__dirname, 'angular4', 'dist')));      
    }else{
        app.use(express.static(path.join(__dirname, 'angular2', 'dist')));      
    }
    next();
});

In this code when you found subdomain1 you serve angular4 app else angular2 app. I hope this will resolve your problem.

Aabid
  • 953
  • 5
  • 23