Skip to content

Commit

Permalink
refactor: remove killable in favor of mehtod
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Aug 17, 2021
1 parent f94b84f commit 1e7d243
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
28 changes: 26 additions & 2 deletions lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const util = require("util");
const fs = require("graceful-fs");
const ipaddr = require("ipaddr.js");
const internalIp = require("internal-ip");
const killable = require("killable");
const express = require("express");
const { validate } = require("schema-utils");
const schema = require("./options.json");
Expand Down Expand Up @@ -61,6 +60,31 @@ class Server {
return /^[a-zA-Z][a-zA-Z\d+\-.]*:/.test(URL);
}

static killable(server) {
let sockets = [];

server.on("connection", (socket) => {
// add socket to list
sockets.push(socket);

socket.once("close", () => {
// remove socket from list
sockets.splice(sockets.indexOf(socket), 1);
});
});

server.kill = (cb) => {
server.close(cb);
sockets.forEach((socket) => {
socket.destroy();
});
// reset so the server can be restarted
sockets = [];
};

return server;
}

static async getHostname(hostname) {
if (hostname === "local-ip") {
return (await internalIp.v4()) || (await internalIp.v6()) || "0.0.0.0";
Expand Down Expand Up @@ -682,7 +706,7 @@ class Server {
this.setupFeatures();
this.createServer();

killable(this.server);
Server.killable(this.server);

if (this.options.setupExitSignals) {
const signals = ["SIGINT", "SIGTERM"];
Expand Down
11 changes: 0 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
"http-proxy-middleware": "^2.0.0",
"internal-ip": "^6.2.0",
"ipaddr.js": "^2.0.1",
"killable": "^1.0.1",
"open": "^8.0.9",
"p-retry": "^4.5.0",
"portfinder": "^1.0.28",
Expand Down

0 comments on commit 1e7d243

Please sign in to comment.