Skip to content

Commit 36226da

Browse files
committed
[dist] Complete JSHint compliance except for too many var statements
1 parent 46c184c commit 36226da

File tree

10 files changed

+166
-156
lines changed

10 files changed

+166
-156
lines changed

lib/node-http-proxy.js

+40-41
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ exports.createServer = function () {
7979
case 'number': port = arg; break;
8080
case 'object': options = arg || {}; break;
8181
case 'function': callback = arg; handlers.push(callback); break;
82-
};
82+
}
8383
});
84-
84+
8585
//
8686
// Helper function to create intelligent error message(s)
8787
// for the very liberal arguments parsing performed by
@@ -90,36 +90,35 @@ exports.createServer = function () {
9090
function validArguments() {
9191
var conditions = {
9292
'port and host': function () {
93-
return port && host;
93+
return port && host;
9494
},
9595
'options.target or options.router': function () {
96-
return options && (options.router ||
96+
return options && (options.router ||
9797
(options.target && options.target.host && options.target.port));
9898
},
9999
'or proxy handlers': function () {
100100
return handlers && handlers.length;
101101
}
102-
}
103-
102+
};
103+
104104
var missing = Object.keys(conditions).filter(function (name) {
105105
return !conditions[name]();
106106
});
107-
107+
108108
if (missing.length === 3) {
109109
message = 'Cannot proxy without ' + missing.join(', ');
110110
return false;
111111
}
112-
112+
113113
return true;
114-
}
115-
114+
}
115+
116116
if (!validArguments()) {
117117
//
118-
// If `host`, `port` and `options` are all not passed (with valid
118+
// If `host`, `port` and `options` are all not passed (with valid
119119
// options) then this server is improperly configured.
120120
//
121121
throw new Error(message);
122-
return;
123122
}
124123

125124
//
@@ -130,7 +129,7 @@ exports.createServer = function () {
130129
options.target = options.target || {};
131130
options.target.port = options.target.port || port;
132131
options.target.host = options.target.host || host;
133-
132+
134133
if (options.target && options.target.host && options.target.port) {
135134
//
136135
// If an explicit `host` and `port` combination has been passed
@@ -148,31 +147,31 @@ exports.createServer = function () {
148147
// we have to assume that this is a "go-anywhere" Proxy (i.e. a `RoutingProxy`).
149148
//
150149
proxy = new RoutingProxy(options);
151-
150+
152151
if (options.router) {
153152
//
154-
// If a routing table has been supplied than we assume
153+
// If a routing table has been supplied than we assume
155154
// the user intends us to add the "proxy" middleware layer
156-
// for them
155+
// for them
157156
//
158157
handlers.push(function (req, res) {
159158
proxy.proxyRequest(req, res);
160159
});
161-
160+
162161
proxy.on('routes', function (routes) {
163162
server.emit('routes', routes);
164163
});
165-
}
164+
}
166165
}
167-
166+
168167
//
169168
// Create the `http[s].Server` instance which will use
170169
// an instance of `httpProxy.HttpProxy`.
171170
//
172-
handler = handlers.length > 1
171+
handler = handlers.length > 1
173172
? exports.stack(handlers, proxy)
174173
: function (req, res) { handlers[0](req, res, proxy) };
175-
174+
176175
server = options.https
177176
? https.createServer(options.https, handler)
178177
: http.createServer(handler);
@@ -184,8 +183,8 @@ exports.createServer = function () {
184183
if (!callback) {
185184
//
186185
// If an explicit callback has not been supplied then
187-
// automagically proxy the request using the `HttpProxy`
188-
// instance we have created.
186+
// automagically proxy the request using the `HttpProxy`
187+
// instance we have created.
189188
//
190189
server.on('upgrade', function (req, socket, head) {
191190
proxy.proxyWebSocketRequest(req, socket, head);
@@ -222,7 +221,7 @@ exports.createServer = function () {
222221
//
223222
exports.buffer = function (obj) {
224223
var events = [],
225-
onData,
224+
onData,
226225
onEnd;
227226

228227
obj.on('data', onData = function (data, encoding) {
@@ -240,11 +239,11 @@ exports.buffer = function (obj) {
240239
},
241240
destroy: function () {
242241
this.end();
243-
this.resume = function () {
244-
console.error("Cannot resume buffer after destroying it.");
245-
};
246-
247-
onData = onEnd = events = obj = null;
242+
this.resume = function () {
243+
console.error("Cannot resume buffer after destroying it.");
244+
};
245+
246+
onData = onEnd = events = obj = null;
248247
},
249248
resume: function () {
250249
this.end();
@@ -278,10 +277,10 @@ exports.setMaxSockets = function (value) {
278277
//
279278
// ### function stack (middlewares, proxy)
280279
// #### @middlewares {Array} Array of functions to stack.
281-
// #### @proxy {HttpProxy|RoutingProxy} Proxy instance to
280+
// #### @proxy {HttpProxy|RoutingProxy} Proxy instance to
282281
// Iteratively build up a single handler to the `http.Server`
283282
// `request` event (i.e. `function (req, res)`) by wrapping
284-
// each middleware `layer` into a `child` middleware which
283+
// each middleware `layer` into a `child` middleware which
285284
// is in invoked by the parent (i.e. predecessor in the Array).
286285
//
287286
// adapted from https://github.com/creationix/stack
@@ -295,17 +294,17 @@ exports.stack = function stack (middlewares, proxy) {
295294
if (err) {
296295
if (res._headerSent) {
297296
res.destroy();
298-
}
297+
}
299298
else {
300299
res.statusCode = 500;
301300
res.setHeader('Content-Type', 'text/plain');
302301
res.end('Internal Server Error');
303302
}
304-
303+
305304
console.error('Error in middleware(s): %s', err.stack);
306305
return;
307306
}
308-
307+
309308
if (child) {
310309
child(req, res);
311310
}
@@ -344,29 +343,29 @@ exports._getAgent = function _getAgent (options) {
344343
if (!options || !options.host) {
345344
throw new Error('`options.host` is required to create an Agent.');
346345
}
347-
346+
348347
if (!options.port) {
349348
options.port = options.https ? 443 : 80;
350349
}
351350

352351
var Agent = options.https ? https.Agent : http.Agent,
353352
agent;
354353

355-
agent = new Agent({
356-
host: options.host,
354+
agent = new Agent({
355+
host: options.host,
357356
port: options.port
358357
});
359358

360359
agent.maxSockets = options.maxSockets || maxSockets;
361360

362361
return agent;
363-
}
362+
};
364363

365364
//
366365
// ### function _getProtocol (options)
367366
// #### @options {Object} Options for the proxy target.
368-
// Returns the appropriate node.js core protocol module (i.e. `http` or `https`)
369-
// based on the `options` supplied.
367+
// Returns the appropriate node.js core protocol module (i.e. `http` or `https`)
368+
// based on the `options` supplied.
370369
//
371370
exports._getProtocol = function _getProtocol (options) {
372371
return options.https ? https : http;
@@ -382,7 +381,7 @@ exports._getProtocol = function _getProtocol (options) {
382381
//
383382
exports._getBase = function _getBase (options) {
384383
var result = function () {};
385-
384+
386385
if (options.https && typeof options.https === 'object') {
387386
['ca', 'cert', 'key'].forEach(function (key) {
388387
if (options.https[key]) {

lib/node-http-proxy/http-proxy.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,10 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
222222
// origin of the host header to the target URL! Please
223223
// don't revert this without documenting it!
224224
//
225-
if(this.changeOrigin)
225+
if (this.changeOrigin) {
226226
outgoing.headers.host = this.target.host + ':' + this.target.port;
227-
227+
}
228+
228229
//
229230
// Open new HTTP request to internal resource with will act
230231
// as a reverse proxy pass
@@ -287,12 +288,13 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
287288
// already been called and the 'error' event listener
288289
// removed.
289290
//
290-
var ended = false
291+
var ended = false;
291292
response.on('close', function () {
292-
if(!ended) response.emit('end')
293-
})
293+
if (!ended) { response.emit('end') }
294+
});
295+
294296
response.on('end', function () {
295-
ended = true
297+
ended = true;
296298
if (!errState) {
297299
reverseProxy.removeListener('error', proxyError);
298300

@@ -566,11 +568,11 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer)
566568
proxySocket.end();
567569
detach();
568570
});
569-
};
571+
}
570572

571573
function getPort (port) {
572574
port = port || 80;
573-
return port - 80 === 0 ? '' : ':' + port
575+
return port - 80 === 0 ? '' : ':' + port;
574576
}
575577

576578
//

lib/node-http-proxy/proxy-table.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ ProxyTable.prototype.getProxyLocation = function (req) {
165165
}
166166

167167
var target = req.headers.host.split(':')[0];
168-
if (this.hostnameOnly == true) {
168+
if (this.hostnameOnly === true) {
169169
if (this.router.hasOwnProperty(target)) {
170170
var location = this.router[target].split(':'),
171171
host = location[0],

lib/node-http-proxy/routing-proxy.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ RoutingProxy.prototype.close = function () {
167167
//
168168
RoutingProxy.prototype.proxyRequest = function (req, res, options) {
169169
options = options || {};
170+
171+
var location;
170172

171173
//
172174
// Check the proxy table for this instance to see if we need
@@ -237,6 +239,10 @@ RoutingProxy.prototype.proxyRequest = function (req, res, options) {
237239
RoutingProxy.prototype.proxyWebSocketRequest = function (req, socket, head, options) {
238240
options = options || {};
239241

242+
var location,
243+
proxy,
244+
key;
245+
240246
if (this.proxyTable && !options.host) {
241247
location = this.proxyTable.getProxyLocation(req);
242248

@@ -248,8 +254,7 @@ RoutingProxy.prototype.proxyWebSocketRequest = function (req, socket, head, opti
248254
options.host = location.host;
249255
}
250256

251-
var key = this._getKey(options),
252-
proxy;
257+
key = this._getKey(options);
253258

254259
if (!this.proxies[key]) {
255260
this.add(options);
@@ -270,11 +275,10 @@ RoutingProxy.prototype._getKey = function (options) {
270275
if (!options || ((!options.host || !options.port)
271276
&& (!options.target || !options.target.host || !options.target.port))) {
272277
throw new Error('options.host and options.port or options.target are required.');
273-
return;
274278
}
275279

276280
return [
277281
options.host || options.target.host,
278282
options.port || options.target.port
279283
].join(':');
280-
}
284+
};

0 commit comments

Comments
 (0)