Thanks Zlatko Đurić . I think I will try the ngnix route!

On Wednesday, June 21, 2017 at 1:16:28 AM UTC-7, Zlatko Đurić wrote:
>
> Hi Tito,
>
> Congratulations on your first production deployment! :)
>
> There are multiple ways to run multiple "apps" from one Node (express) 
> app. You're saying Angular apps, but it seems like Node.js is involved too, 
> so I'll try to address some cases. If you have one very specific 
>
> TL;DR:
> - if it's just angular apps, serve app.use('/app-virtual-path', 
> express.static('/path/to/app'))
> - if it's Node.js code as well, write those in their own modules, and 
> export their routers (not the whole express apps), than mount the 
> individual routers on a global express server.
>
>
> If it's just multiple angular apps, than it's pretty simple - serve apps 
> on different routes (or even domains/network interfaces/whatnot).
>
> E.g. simplest way to serve those with Node on different paths, e.g.
> server.example.com/app1 -> serves angular app 1
> server.example.com/app2 -> serves angular app 2
> etc.
>
> app.use('/app1', express.static('/path/to/app1'));
> app.use('/app2', express.static('/path/to/app2'));
> // ...
> app.use('/appN', express.static('/path/to/appN'));
>
> Basically, every app is served in its own virtual path.
>
> Alternatively, you can serve the angular apps on different subdomains, 
> e.g.:
> app1.server.com -> serves app1
> app2.server.com -> serves app2.
>
> How to do this depends on your server setup. You can route it directly 
> with node, using something like this: 
> https://www.npmjs.com/package/express-subdomain. Alternatively, you can 
> use the simpler version above, but than use some rewrite rule on the 
> reverse proxy that's in front of node (such as nginx, or IIS since you're 
> on windows).
>
> If you also need some server-side specific code, those separate routes 
> handle the stuff, for you. For clarity, maybe just separate those in their 
> own files/folders with their own routers, than mount it all on one global 
> express router and handle routing properly. The added benefit of running it 
> all on a single node instance is that you get to share common middleware 
> like authentication or authorization, which is likely to be useful in an 
> environment that you describe.
>
> Example:
>
> // app1.js
> const router = require('express').Router();
> router.use('/app-specific-endpoint', (req, res) => {
>   res.json({ message: 'Here is something that is specific for this app' });
> });
> router.use(express.static('/path/to/angular/code'));
> module.exports = { router };helps a bit
>
> // app2 -> the same, just for the different angular app.
> const router = ...
> module.exports = { router };
>
> // global express app file, e.g. server.js
> const express = require('express')
> const app = express();
> const middleware = require('./middleware/'); // optionally, if ou need it.
> const router1 = require('./app1').router;
> const router2 = require('./app2').router;
>
> app.use(middleware.auth()); 
> app.use('/angular-app-1', router1);
> app.use('/angular-app-2', middleware.hasRole('admin')); // specific for 
> app2, say, permissions check
> app.use('/angular-app-2', router2);
> const port = 8080;
> app.listen(port, (err) => console.log(err || `Listening on ${port}`));
>
> I hope this gives you ideas on how to start. If you share more details, 
> maybe you can get more specific answers.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to angular+unsubscr...@googlegroups.com.
To post to this group, send email to angular@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to