Skip to content

Commit b66bbd2

Browse files
committed
npm run fmt
maybe prettier output changed?
1 parent d41f67c commit b66bbd2

11 files changed

+378
-358
lines changed

bin/configurable-http-proxy

+17-19
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ args
6767
"--redirect-port <redirect-port>",
6868
"Redirect HTTP requests on this port to the server on HTTPS"
6969
)
70-
.option(
71-
"--redirect-to <port>",
72-
"Redirect HTTP requests from --redirect-port to this port")
70+
.option("--redirect-to <port>", "Redirect HTTP requests from --redirect-port to this port")
7371
.option("--pid-file <pid-file>", "Write our PID to a file")
7472
// passthrough http-proxy options
7573
.option("--no-x-forward", "Don't add 'X-forward-' headers to proxied requests")
@@ -84,7 +82,8 @@ args
8482
.option(
8583
"--custom-header <header>",
8684
"Custom header to add to proxied requests. Use same option for multiple headers (--custom-header k1:v1 --custom-header k2:v2)",
87-
collectHeadersIntoObject, {}
85+
collectHeadersIntoObject,
86+
{}
8887
)
8988
.option("--insecure", "Disable SSL cert verification")
9089
.option("--host-routing", "Use host routing (host as first level of path)")
@@ -110,12 +109,12 @@ args
110109
// collects multiple flags to an object
111110
// --custom-header "k1:v1" --custom-header " k2 : v2 " --> {"k1":"v1","k2":"v2"}
112111
function collectHeadersIntoObject(value, previous) {
113-
var headerParts = value.split(":").map(p => p.trim())
112+
var headerParts = value.split(":").map((p) => p.trim());
114113
if (headerParts.length != 2) {
115114
log.error("A single colon was expected in custom header: " + value);
116115
process.exit(1);
117116
}
118-
previous[headerParts[0]] = headerParts[1]
117+
previous[headerParts[0]] = headerParts[1];
119118
}
120119

121120
args.parse(process.argv);
@@ -206,7 +205,7 @@ if (args.apiSslKey || args.apiSslCert) {
206205
var chain = fs.readFileSync(args.apiSslCa, "utf8");
207206
var ca = [];
208207
var cert = [];
209-
chain.split("\n").forEach(function(line) {
208+
chain.split("\n").forEach(function (line) {
210209
cert.push(line);
211210
if (line.match(/-END CERTIFICATE-/)) {
212211
ca.push(new Buffer(cert.join("\n")));
@@ -241,7 +240,7 @@ if (args.clientSslKey || args.clientSslCert) {
241240
var chain = fs.readFileSync(args.clientSslCa, "utf8");
242241
var ca = [];
243242
var cert = [];
244-
chain.split("\n").forEach(function(line) {
243+
chain.split("\n").forEach(function (line) {
245244
cert.push(line);
246245
if (line.match(/-END CERTIFICATE-/)) {
247246
ca.push(new Buffer(cert.join("\n")));
@@ -357,7 +356,7 @@ if (args.pidFile) {
357356
var fd = fs.openSync(args.pidFile, "w");
358357
fs.writeSync(fd, process.pid.toString());
359358
fs.closeSync(fd);
360-
process.on("exit", function() {
359+
process.on("exit", function () {
361360
log.debug("Removing %s", args.pidFile);
362361
fs.unlinkSync(args.pidFile);
363362
});
@@ -366,9 +365,9 @@ if (args.pidFile) {
366365
// Redirect HTTP to HTTPS on the proxy's port
367366
if (options.redirectPort && listen.port !== 80) {
368367
var http = require("http");
369-
var redirectPort = (options.redirectTo ? options.redirectTo : listen.port);
368+
var redirectPort = options.redirectTo ? options.redirectTo : listen.port;
370369
var server = http
371-
.createServer(function(req, res) {
370+
.createServer(function (req, res) {
372371
var host = req.headers.host.split(":")[0];
373372

374373
// Make sure that when we redirect, it's to the port the proxy is running on
@@ -379,30 +378,29 @@ if (options.redirectPort && listen.port !== 80) {
379378
res.writeHead(301, { Location: "https://" + host + req.url });
380379
res.end();
381380
})
382-
.listen(options.redirectPort, ()=>{
383-
log.info("Added HTTP to HTTPS redirection from "
384-
+ server.address().port
385-
+ " to "
386-
+ redirectPort);
381+
.listen(options.redirectPort, () => {
382+
log.info(
383+
"Added HTTP to HTTPS redirection from " + server.address().port + " to " + redirectPort
384+
);
387385
});
388386
}
389387

390388
// trigger normal exit on SIGINT
391389
// without this, PID cleanup won't fire on SIGINT
392-
process.on("SIGINT", function() {
390+
process.on("SIGINT", function () {
393391
log.warn("Interrupted");
394392
process.exit(2);
395393
});
396394

397395
// trigger normal exit on SIGTERM
398396
// fired on `docker stop` and during Kubernetes pod container evictions
399-
process.on("SIGTERM", function() {
397+
process.on("SIGTERM", function () {
400398
log.warn("Terminated");
401399
process.exit(2);
402400
});
403401

404402
// log uncaught exceptions, don't exit now that setup is complete
405-
process.on("uncaughtException", function(e) {
403+
process.on("uncaughtException", function (e) {
406404
log.error("Uncaught Exception: " + e.message);
407405
if (e.stack) {
408406
log.error(e.stack);

lib/configproxy.js

+35-36
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ var http = require("http"),
2323
function bound(that, method) {
2424
// bind a method, to ensure `this=that` when it is called
2525
// because prototype languages are bad
26-
return function() {
26+
return function () {
2727
return method.apply(that, arguments);
2828
};
2929
}
@@ -50,13 +50,13 @@ function fail(req, res, code, msg) {
5050
function jsonHandler(handler) {
5151
// wrap json handler, so the handler is called with parsed data,
5252
// rather than implementing streaming parsing in the handler itself
53-
return function(req, res) {
53+
return function (req, res) {
5454
var args = argumentsArray(arguments);
5555
var buf = "";
56-
req.on("data", function(chunk) {
56+
req.on("data", function (chunk) {
5757
buf += chunk;
5858
});
59-
req.on("end", function() {
59+
req.on("end", function () {
6060
var data;
6161
try {
6262
data = JSON.parse(buf) || {};
@@ -72,7 +72,7 @@ function jsonHandler(handler) {
7272

7373
function authorized(method) {
7474
// decorator for token-authorized handlers
75-
return function(req, res) {
75+
return function (req, res) {
7676
if (!this.authToken) {
7777
return method.apply(this, arguments);
7878
}
@@ -105,8 +105,8 @@ function parseHost(req) {
105105
function camelCaseify(options) {
106106
// camelCaseify options dict, for backward compatibility
107107
let camelOptions = {};
108-
Object.keys(options).forEach(key => {
109-
const camelKey = key.replace(/_(.)/g, function(match, part, offset, string) {
108+
Object.keys(options).forEach((key) => {
109+
const camelKey = key.replace(/_(.)/g, function (match, part, offset, string) {
110110
return part.toUpperCase();
111111
});
112112
if (camelKey !== key) {
@@ -117,7 +117,7 @@ function camelCaseify(options) {
117117
return camelOptions;
118118
}
119119

120-
const loadStorage = options => {
120+
const loadStorage = (options) => {
121121
if (options.storageBackend) {
122122
const BackendStorageClass = require(options.storageBackend);
123123
return new BackendStorageClass(options);
@@ -158,14 +158,14 @@ class ConfigurableProxy extends EventEmitter {
158158
// Mock the statsd object, rather than pepper the codebase with
159159
// null checks. FIXME: Maybe use a JS Proxy object (if available?)
160160
this.statsd = {
161-
increment: function() {},
162-
decrement: function() {},
163-
timing: function() {},
164-
gauge: function() {},
165-
set: function() {},
166-
createTimer: function() {
161+
increment: function () {},
162+
decrement: function () {},
163+
timing: function () {},
164+
gauge: function () {},
165+
set: function () {},
166+
createTimer: function () {
167167
return {
168-
stop: function() {},
168+
stop: function () {},
169169
};
170170
},
171171
};
@@ -193,8 +193,8 @@ class ConfigurableProxy extends EventEmitter {
193193
],
194194
];
195195

196-
var logErrors = handler => {
197-
return function(req, res) {
196+
var logErrors = (handler) => {
197+
return function (req, res) {
198198
function logError(e) {
199199
that.log.error("Error in handler for " + req.method + " " + req.url + ": %s", e);
200200
}
@@ -227,7 +227,7 @@ class ConfigurableProxy extends EventEmitter {
227227
// proxy websockets
228228
this.proxyServer.on("upgrade", bound(this, this.handleProxyWs));
229229

230-
this.proxy.on("proxyRes", function(proxyRes, req, res) {
230+
this.proxy.on("proxyRes", function (proxyRes, req, res) {
231231
that.statsd.increment("requests." + proxyRes.statusCode, 1);
232232
});
233233
}
@@ -267,7 +267,7 @@ class ConfigurableProxy extends EventEmitter {
267267
// remove a route from the routing table
268268
var routes = this._routes;
269269

270-
return routes.get(path).then(result => {
270+
return routes.get(path).then((result) => {
271271
if (result) {
272272
this.log.info("Removing route %s", path);
273273
return routes.remove(path);
@@ -278,7 +278,7 @@ class ConfigurableProxy extends EventEmitter {
278278
getRoute(req, res, path) {
279279
// GET a single route
280280
path = this._routes.cleanPath(path);
281-
return this._routes.get(path).then(function(route) {
281+
return this._routes.get(path).then(function (route) {
282282
if (!route) {
283283
res.writeHead(404);
284284
res.end();
@@ -319,11 +319,11 @@ class ConfigurableProxy extends EventEmitter {
319319
}
320320
res.writeHead(200, { "Content-Type": "application/json" });
321321

322-
return this._routes.getAll().then(routes => {
322+
return this._routes.getAll().then((routes) => {
323323
var results = {};
324324

325325
if (inactiveSince) {
326-
Object.keys(routes).forEach(function(path) {
326+
Object.keys(routes).forEach(function (path) {
327327
if (routes[path].last_activity < inactiveSince) {
328328
results[path] = routes[path];
329329
}
@@ -349,7 +349,7 @@ class ConfigurableProxy extends EventEmitter {
349349
}
350350

351351
var that = this;
352-
return this.addRoute(path, data).then(function() {
352+
return this.addRoute(path, data).then(function () {
353353
res.writeHead(201);
354354
res.end();
355355
that.statsd.increment("api.route.add", 1);
@@ -359,7 +359,7 @@ class ConfigurableProxy extends EventEmitter {
359359
deleteRoutes(req, res, path) {
360360
// DELETE removes an existing route
361361

362-
return this._routes.get(path).then(result => {
362+
return this._routes.get(path).then((result) => {
363363
var p, code;
364364
if (result) {
365365
p = this.removeRoute(path);
@@ -382,7 +382,7 @@ class ConfigurableProxy extends EventEmitter {
382382
var basePath = this.hostRouting ? "/" + parseHost(req) : "";
383383
var path = basePath + decodeURIComponent(URL.parse(req.url).pathname);
384384

385-
return this._routes.getTarget(path).then(function(route) {
385+
return this._routes.getTarget(path).then(function (route) {
386386
timer.stop();
387387
if (route) {
388388
return {
@@ -399,7 +399,7 @@ class ConfigurableProxy extends EventEmitter {
399399

400400
return routes
401401
.get(prefix)
402-
.then(function(result) {
402+
.then(function (result) {
403403
if (result) {
404404
return routes.update(prefix, { last_activity: new Date() });
405405
}
@@ -448,20 +448,20 @@ class ConfigurableProxy extends EventEmitter {
448448
urlSpec.pathname = urlSpec.pathname + code.toString();
449449
var secure = /https/gi.test(urlSpec.protocol) ? true : false;
450450
var url = URL.format(urlSpec);
451-
var errorRequest = (secure ? https : http).request(url, function(upstream) {
452-
["content-type", "content-encoding"].map(function(key) {
451+
var errorRequest = (secure ? https : http).request(url, function (upstream) {
452+
["content-type", "content-encoding"].map(function (key) {
453453
if (!upstream.headers[key]) return;
454454
if (res.setHeader) res.setHeader(key, upstream.headers[key]);
455455
});
456456
if (res.writeHead) res.writeHead(code);
457-
upstream.on("data", data => {
457+
upstream.on("data", (data) => {
458458
if (res.write) res.write(data);
459459
});
460460
upstream.on("end", () => {
461461
if (res.end) res.end();
462462
});
463463
});
464-
errorRequest.on("error", e => {
464+
errorRequest.on("error", (e) => {
465465
// custom error failed, fallback on default
466466
this.log.error("Failed to get custom error page: %s", e);
467467
this._handleProxyErrorDefault(code, kind, req, res);
@@ -504,16 +504,15 @@ class ConfigurableProxy extends EventEmitter {
504504
var args = Array.prototype.slice.call(arguments, 1);
505505

506506
// get the proxy target
507-
return this.targetForReq(req).then(match => {
507+
return this.targetForReq(req).then((match) => {
508508
if (!match) {
509509
that.handleProxyError(404, kind, req, res);
510510
return;
511511
}
512512

513513
if (kind === "web") {
514514
that.emit("proxyRequest", req, res);
515-
}
516-
else {
515+
} else {
517516
that.emit("proxyRequestWs", req, res, args[2]);
518517
}
519518
var prefix = match.prefix;
@@ -534,7 +533,7 @@ class ConfigurableProxy extends EventEmitter {
534533
args.push({ target: target });
535534

536535
// add error handling
537-
args.push(function(e) {
536+
args.push(function (e) {
538537
that.handleProxyError(503, kind, req, res, e);
539538
});
540539

@@ -544,11 +543,11 @@ class ConfigurableProxy extends EventEmitter {
544543
that.proxy[kind].apply(that.proxy, args);
545544

546545
// update timestamp on any request/reply data as well (this includes websocket data)
547-
req.on("data", function() {
546+
req.on("data", function () {
548547
that.updateLastActivity(prefix);
549548
});
550549

551-
res.on("data", function() {
550+
res.on("data", function () {
552551
that.updateLastActivity(prefix);
553552
});
554553

lib/log.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
var strftime = require("strftime"),
33
winston = require("winston");
44

5-
const simpleFormat = winston.format.printf(info => {
5+
const simpleFormat = winston.format.printf((info) => {
66
// console.log(info);
77
return `${info.timestamp} [${info.label}] ${info.level}: ${info.message}`;
88
});

lib/store.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
var trie = require("./trie.js");
44

5-
var NotImplemented = function(name) {
5+
var NotImplemented = function (name) {
66
return {
77
name: "NotImplementedException",
88
message: "method '" + name + "' not implemented",
@@ -31,7 +31,7 @@ class BaseStore {
3131
// default get implementation derived from getAll
3232
// only needs overriding if a more efficient implementation is available
3333
path = this.cleanPath(path);
34-
return this.getAll().then(routes => routes[path]);
34+
return this.getAll().then((routes) => routes[path]);
3535
}
3636

3737
cleanPath(path) {

0 commit comments

Comments
 (0)