forked from microting/eform-angular-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
39 lines (34 loc) · 1.04 KB
/
server.js
File metadata and controls
39 lines (34 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const express = require('express');
const compression = require('compression');
const path = require('path');
var httpProxy = require('http-proxy');
const app = express();
const defaultPort = process.env.PORT || $$port$$;
// proxy
var apiProxy = httpProxy.createProxyServer({changeOrigin: true});
var apiForwardingUrl = 'http://localhost:$$apiport$$/';
apiProxy.on('error', function(e) {
console.error('Error:');
console.info(e);
console.log('-------------------------------------');
});
// gzip
// app.use(compression());
app.use(express.static(__dirname + '/dist'));
// api handler
app.all('/api/*', function (req, res) {
try {
apiProxy.web(req, res, {target: apiForwardingUrl});
} catch (ex) {
return next(ex)
}
});
// so that PathLocationStrategy can be used
app.all('/*', function (req, res) {
res.removeHeader('accept-encoding');
res.sendFile(path.join(__dirname + '/dist/index.html'));
});
// Start the app by listening
app.listen(defaultPort, function () {
console.log('Application started on port: ' + defaultPort);
});