-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproxy-cw.js
44 lines (33 loc) · 1.07 KB
/
proxy-cw.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
'use strict';
var http = require('http');
var config = {};
function proxy(client_req, client_res) {
var options = {
hostname: config.hostname,
port: config.port,
path: client_req.url.replace(config.basePathRe, ''),
headers: client_req.headers
};
http.request(options, function(res) {
copyHeaders(res, client_res);
res.pipe(client_res);
}).end();
}
proxy.configure = function configure(mainConfig) {
config.hostname = mainConfig.proxyHostname;
config.port = mainConfig.proxyPort;
config.basePathRe = mainConfig.proxyRe;
};
function copyHeaders(reqFrom, reqTo) {
var headersOfInterest = ['date', 'content-type',
'content-length',
'date', 'last-modified',
'set-cookie'];
var headersFrom = reqFrom.headers;
for (var i = 0, header ; header = headersOfInterest[i] ; i++ ) {
if (header in headersFrom) {
reqTo.setHeader(header, headersFrom[header]);
}
}
}
module.exports = proxy;