-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathconfig.js
110 lines (99 loc) · 2.62 KB
/
config.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
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
"use strict";
var url = require("url");
var utils = require("./utils");
var errors = require("./errors");
var merge = require("lodash.merge");
var defaults = {
/**
* Error handler for proxy server.
*/
errHandler: errors,
/**
* White-list for paths to open to middleware
*/
whitelist: [],
/**
* Black-list for paths to open to middleware
*/
blacklist: [],
/**
* Cookie options
*/
cookies: {
/**
* Strip the domain attribute from cookies
* This is `true` by default to help with logins etc
*/
stripDomain: true
},
/**
* Default req headers
* @param config
* @returns {{host: string, accept-encoding: string, agent: boolean}}
*/
reqHeaders: function (config) {
return {
"host": config.urlObj.host,
"accept-encoding": "identity", // disable any compression
"agent": false
};
},
/**
* Serve any static files here
*/
staticFiles: {},
/**
*
*/
middleware: [utils.handleIe],
/**
* Proxy Options that get passed along to http-proxy
*/
proxyOptions: {
xfwd: false,
headers: {},
target: "",
// secure: false - This forces http-proxy to set rejectUnauthorized: false which allows self-signed certs
// which we are fine with considering this is a development tool, not to be used in production. :)
secure: false,
ws: true
},
/**
* Any transformations to occur after the server has sent
* its response
*/
proxyRes: [
utils.checkCookies,
utils.removeExcludedHeaders,
utils.handleRedirect
],
/**
* Remove content-length headers as we've rewritten the response
*/
excludedHeaders: [
"content-length", "content-encoding"
]
};
/**
* @param {String} target - a url such as http://www.bbc.co.uk or http://localhost:8181
* @param {Object} [userConfig]
* @returns {Object}
*/
module.exports = function (target, userConfig) {
// Merge defaults with user config
// + add extra needed config options
var config = merge({}, defaults, userConfig, function(a, b) {
if (Array.isArray(a)) {
return a.concat(b);
}
});
var urlObj = url.parse(target);
var _target = urlObj.protocol + "//" + urlObj.hostname;
config.urlObj = urlObj;
config.hostHeader = utils.getProxyHost(urlObj);
if (urlObj.port) {
_target = _target + ":" + urlObj.port;
}
config.target = _target;
return config;
};