Run Angular build using Nodejs

Run Angular build using Node server :

server.js

const express = require('express');
const app = express();

app.set('port', process.env.PORT||4200);

app.listen(app.get('port'), () => {
    console.log('Server started!');
});

app.use(express.static('dist/'))
app.use(function(req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Headers", "Origin, authentication, X-Requested-With, Content-Type, Accept");
  next();
});

app.route('/').get((req, res) => {
  var auth_user = req.headers['auth_user'] || 'admin-node';
  var host = req.headers['host'] || 'localhost';
  var result = {"user":auth_user,"host":host};
  res.send(result);
});

Comments

Popular posts from this blog

Module Bundel

Power of async and Promise