slower 1.1.21 → 1.1.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/router.js +9 -15
- package/package.json +1 -1
package/lib/router.js
CHANGED
|
@@ -26,15 +26,6 @@ class SlowerRouter {
|
|
|
26
26
|
];
|
|
27
27
|
|
|
28
28
|
static mime_table = mimetable;
|
|
29
|
-
// {
|
|
30
|
-
// 'txt' : ['text/plain', 'utf-8'],
|
|
31
|
-
// 'html': ['text/html', 'utf-8'],
|
|
32
|
-
// 'js' : ['text/javascript', 'utf-8'],
|
|
33
|
-
// 'css' : ['text/css', 'utf-8'],
|
|
34
|
-
// 'ico' : ['image/png'],
|
|
35
|
-
// 'json': ['application/json'],
|
|
36
|
-
// 'default': ['application/octet-stream']
|
|
37
|
-
// }
|
|
38
29
|
|
|
39
30
|
constructor () {
|
|
40
31
|
this.strictHeaders = false;
|
|
@@ -44,6 +35,7 @@ class SlowerRouter {
|
|
|
44
35
|
this.allowedMethods = clone(SlowerRouter.http_methods);
|
|
45
36
|
this.blockedMethodCallback = noop;
|
|
46
37
|
this.tls = { use: false, key: null, cert: null };
|
|
38
|
+
this.server = null;
|
|
47
39
|
}
|
|
48
40
|
|
|
49
41
|
enableStrictHeaders () {
|
|
@@ -372,14 +364,12 @@ class SlowerRouter {
|
|
|
372
364
|
let fallback = this.fallback;
|
|
373
365
|
let allowedMethods = this.allowedMethods;
|
|
374
366
|
let blockedMethodCallback = this.blockedMethodCallback;
|
|
375
|
-
|
|
376
|
-
let server;
|
|
377
367
|
|
|
378
368
|
if (this.tls.use && this.tls.cert && this.tls.key) {
|
|
379
|
-
server = https.createServer({ key:this.tls.key, cert: this.tls.cert }, mainServerHandler);
|
|
369
|
+
this.server = https.createServer({ key:this.tls.key, cert: this.tls.cert }, mainServerHandler);
|
|
380
370
|
|
|
381
371
|
} else {
|
|
382
|
-
server = http.createServer({}, mainServerHandler);
|
|
372
|
+
this.server = http.createServer({}, mainServerHandler);
|
|
383
373
|
}
|
|
384
374
|
|
|
385
375
|
function mainServerHandler (req, res) {
|
|
@@ -425,11 +415,15 @@ class SlowerRouter {
|
|
|
425
415
|
}
|
|
426
416
|
}
|
|
427
417
|
|
|
428
|
-
callback(server);
|
|
418
|
+
callback(this.server);
|
|
429
419
|
if (!host) host = undefined; // Turn falsy values into undefined, for default behaviour
|
|
430
|
-
server.listen(port, host);
|
|
420
|
+
this.server.listen(port, host);
|
|
431
421
|
return this;
|
|
432
422
|
}
|
|
423
|
+
|
|
424
|
+
close = function () {
|
|
425
|
+
this.server.close();
|
|
426
|
+
}
|
|
433
427
|
}
|
|
434
428
|
|
|
435
429
|
const Slower = function () { return new SlowerRouter(); }
|