-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
45 lines (33 loc) · 1.09 KB
/
server.js
File metadata and controls
45 lines (33 loc) · 1.09 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
var Express = require("express");
var http = require("http");
var url = require("url");
var server = Express.createServer();
var mountPoint = "/clsi";
config = {
clsiUrl : "http://localhost:3002"
}
server.all(mountPoint + "/*", function(req, res, next) {
var backend = http.createClient(
url.parse(config.clsiUrl).port,
url.parse(config.clsiUrl).hostname
)
backendUrl = req.url.slice(mountPoint.length);
var proxyRequest = backend.request(req.method, backendUrl, req.headers);
proxyRequest.addListener("response", function(proxyResponse) {
proxyResponse.addListener("data", function(chunk) {
res.write(chunk, "binary");
});
proxyResponse.addListener("end", function() {
res.end();
});
res.writeHead(proxyResponse.statusCode, proxyResponse.headers);
});
req.addListener("data", function(chunk) {
proxyRequest.write(chunk, "binary");
});
req.addListener("end", function() {
proxyRequest.end();
});
});
server.use(Express.static(__dirname));
server.listen(8000);