-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathserver.js
More file actions
68 lines (54 loc) · 1.64 KB
/
server.js
File metadata and controls
68 lines (54 loc) · 1.64 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
67
68
"use strict";
var raptureAuth = require("./node_modules_incapture/core-auth"),
httpProxy = require("http-proxy"),
express = require("express"),
compression = require("compression"),
forwardingUrl,
routes,
apiProxy,
app;
forwardingUrl = raptureAuth.getConfig()["forwardingUrl"];
routes = [
{
path: "/login/*",
target: forwardingUrl
},
{
path: "/webscript/*",
target: forwardingUrl
},
{
path: "/blob/*",
target: forwardingUrl
},
{
path: "/blobupload",
target: forwardingUrl
}
];
// set connection
raptureAuth.setConnection();
// rapture api login (this will also install scripts from the specified base directory)
raptureAuth.apiLogin({projectDir: __dirname, scriptsBaseDir: "/scripts"});
apiProxy = httpProxy.createProxyServer();
app = express();
app.use(compression({threshold: 0}));
app.use(express.static(__dirname + "/public"));
apiProxy.on("error", function(e) {
console.log("ERROR: Handling proxy connection failed - " + e);
});
// define Express routes
for (var idx = 0; idx < routes.length; idx++)
defineExpressRoute(routes[idx]["path"], routes[idx]["target"]);
function defineExpressRoute(path, target) {
app.all(path, function(req, res) {
apiProxy.web(req, res, {
target: target
});
});
}
app.use(function(req, res, next) {
res.status(404).sendFile(__dirname + "/public/404.html");
});
app.listen(raptureAuth.getConfig()["webPort"]);
console.log("INFO: App listening on port - " + raptureAuth.getConfig()["webPort"]);