ranyeli
10/2/2017 - 8:30 PM

express server

Server that allows angular to do the routing and meant to run the production build + proxy for api service

var express = require('express');
var requestProxy = require('express-request-proxy');
var path = require('path');
var http = require('http');
// var fs = require('fs');
// var proxy = JSON.parse(fs.readFileSync(__dirname + '/dist/assets/resource.json', 'utf8'));

app = express();

// forward all routes ending in /api/* to the url set
app.all('/api/*', requestProxy({
    url: "https://invoice-backend-jar.herokuapp.com/" + "api/*"
  }));

app.use(express.static(__dirname + '/dist'));

const port = process.env.PORT || 5000;

app.set('port', port);

app.get('*', function(req, res) {
    res.sendFile(path.join(__dirname + '/dist/index.html'));
});

const server = http.createServer(app);

server.listen(port, () => console.log('Listening on ' + port));