This repository was archived by the owner on Nov 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
66 lines (49 loc) · 1.62 KB
/
server.js
File metadata and controls
66 lines (49 loc) · 1.62 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
var express = require('express');
var httpProxy = require('http-proxy');
var options = {
target : { // options for proxy target
https: true,
port : 443,
host : 'https.host.com',
},
enable : {
xforward: true // enables X-Forwarded-For
},
changeOrigin: true, // changes the origin of the host header to the target URL
timeout: 120000 // override the default 2 minute http socket timeout value in milliseconds
};
var proxy = new httpProxy.RoutingProxy(options);
var https = require('https');
var fs = require('fs');
var sysPath = require('path');
function apiProxy(req, res, next) {
if(req.url.match(new RegExp('^\/someaddresstorereoute'))){
console.log('regex matched /someaddresstorereoute');
proxy.proxyRequest(req, res, {host: 'https.host.com', port: 443});
}else{
next();
}
}
startExpress = function(port, base, path, callback) {
var server;
server = express();
server.use(function(request, response, next) {
response.header('Cache-Control', 'no-cache');
return next();
});
server.use(apiProxy);
server.use(base, express["static"](path));
// server.get("*/jalla", function(request, response) {
// return response.sendfile(sysPath.join(path, 'test2.html'));
// });
server.listen(port, callback);
// https.createServer({}, server);
return server;
};
exports.startServer = function(port, publicPath, callback) {
console.log('Started server.js');
var defaultRoute, expressPort, routes;
expressPort = port;
//routes = config.server.routes || {};
return startExpress(expressPort, '/', publicPath, function(){});
};