To put on a nodejs server:
1- If you are using angular cli run the command to generate the Bundles:
ng build --prod
This will generate the dist folder with all the site static code.
2- Download Node js on your development machine
3-After installing type in the prompt (in the directory a level above the dist folder):
npm init
Answer the console questions (leaving the startup script as index.js)
4- Create an index.js file:
const express = require('express');
const app = express();
app.set('port', 80);
app.use(express.static(__dirname + '/dist'));
app.get('*',function (req, res) {
res.sendFile(__dirname + '/dist/index.html');
});
app.listen(app.get('port'), function() {
console.log('Running on port ', app.get('port'));
});
Your directory structure should be:
home
-dist/
--arquivos html
-index.js
-package.json
To test place run:
npm start
To run a website on each route:
Whereas there will be two dist-site1 and dist_site2 directories
const express = require('express');
const app = express();
app.set('port', 80);
// Servir estático os dois dists em rotas separadas:
app.use('/site1',express.static(__dirname + '/dist_site1/'));
app.use('/site2',express.static(__dirname + '/dist_site2/'));
// Direcionar para um dos sites caso entre com o link do dominio
app.get('/',function (req, res) {
res.redirect('/site1');
});
// Direcionar todas as rotas não interceptadas pelo estático para o angular
app.get('/site1/*',function (req, res) {
res.sendFile(__dirname + '/dist_site1/index.html');
});
// Direcionar todas as rotas não interceptadas pelo estático para o angular
app.get('/site2/*',function (req, res) {
res.sendFile(__dirname + '/dist_site2/index.html');
});
app.listen(app.get('port'), function() {
console.log('Running on port ', app.get('port'));
});
I didn’t quite understand your question, but you should make your local application to then go up to the server. In the same way as using NPM, Bower, Composer, etc.
– Marco Garcia
With angular 2 when Gero build is created the /dist folder where I should put on a Tomcat server for example, as I would do it there?
– Victor César