-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
58 lines (47 loc) · 1.69 KB
/
index.js
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const request = require("request");
const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
const args = process.argv;
if (args[2] == undefined) {
args[2] = 'env=dev';
}
const env_type = args[2].split("=")[1];
var httpProxy = require('http-proxy');
var proxyServer = httpProxy.createProxyServer();
var config_file = require('./abm-config.' + env_type + '.json');
var jsonParser = bodyParser.json();
const app = express();
app.use(express.static('dist'));
app.use('/download/*', function (req, res) {
var url = config_file.url.slice(0, config_file.url.length - 1);
var file = request.get(url + req.originalUrl);
file.pipe(res);
});
app.use('/downloadHermes/*', function (req, res) {
//res.setHeader("Content-Disposition", "attachment; filename=archive.zip;");
// proxyServer.web(req, res, {
// target: config_file.url
// });
var url = config_file.url.slice(0, config_file.url.length - 1);
var file = request.get(url + req.originalUrl);
file.pipe(res);
});
app.all('/rest/*', function (req, res) {
proxyServer.web(req, res, {
target: config_file.url
});
});
//Redirecting all other requests to index.html to make angular work from direct url when served from server.
//https://github.com/angular-ui/ui-router/wiki/Frequently-Asked-Questions#how-to-configure-your-server-to-work-with-html5mode
app.use('/', function (req, res, next) {
res.sendFile('dist/index.html', {
root: __dirname
});
});
proxyServer.on("proxyReq", function (proxyReq, req, res, options) {
//console.log(res);
})
module.exports = app.listen(3000, () => {
console.log('Example app listening on port 3000!')
});