-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
executable file
·33 lines (29 loc) · 1.09 KB
/
server.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
'use strict';
var express = require('express');
var session = require('cookie-session');
var cookieParser = require('cookie-parser');
var bodyParser = require("body-parser");
var path = require('path');
var http = require('http');
var Q = require('q');
var httpProxy = require('http-proxy');
var config = require('./config');
var targetHost = process.env.PROXY_HOST || config.DEFAULT_TARGET_PROXY_HOST;
var publicDir = config.DEFAULT_PUBLIC_PATH;
var proxy = httpProxy.createProxyServer();
var app = express();
app.disable('x-powered-by');
app.use(cookieParser());
app.use(session({secret: require('crypto').randomBytes(20).toString('base64')}));
app.use(express.static(publicDir, {'redirect': false}));
app.get('/', function (req, res) {
res.sendfile(path.join(publicDir, 'index.html'));
});
app.all(config.API_BASE_PATH + "*", function(req, res) {
req.headers.host = targetHost;
req.headers.origin = 'http://' + targetHost;
proxy.web(req, res, {target: req.headers.origin + '/'});
});
app.listen(3000, '0.0.0.0', function () {
console.log("server started at http://127.0.0.1:3000");
});