feat(xo-server): close inactive HTTP connections on stop

This commit is contained in:
Julien Fontanet
2018-03-13 10:22:06 +01:00
parent 1368e3b86d
commit 782505b292
3 changed files with 8 additions and 2 deletions

View File

@@ -101,6 +101,7 @@
"serve-static": "^1.13.1",
"split-lines": "^1.1.0",
"stack-chain": "^2.0.0",
"stoppable": "^1.0.5",
"tar-stream": "^1.5.5",
"through2": "^2.0.3",
"tmp": "^0.0.33",

View File

@@ -9,6 +9,7 @@ import includes from 'lodash/includes'
import proxyConsole from './proxy-console'
import serveStatic from 'serve-static'
import startsWith from 'lodash/startsWith'
import stoppable from 'stoppable'
import WebSocket from 'ws'
import { compile as compilePug } from 'pug'
import { createServer as createProxyServer } from 'http-proxy'
@@ -332,7 +333,7 @@ async function makeWebServerListen (
}
async function createWebServer ({ listen, listenOptions }) {
const webServer = new WebServer()
const webServer = stoppable(new WebServer())
await Promise.all(
mapToArray(listen, opts =>
@@ -565,7 +566,7 @@ export default async function main (args) {
const xo = new Xo(config)
// Register web server close on XO stop.
xo.on('stop', () => pFromCallback(cb => webServer.close(cb)))
xo.on('stop', () => pFromCallback(cb => webServer.stop(cb)))
// Connects to all registered servers.
await xo.start()

View File

@@ -10623,6 +10623,10 @@ stealthy-require@^1.1.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/stealthy-require/-/stealthy-require-1.1.1.tgz#35b09875b4ff49f26a777e509b3090a3226bf24b"
stoppable@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/stoppable/-/stoppable-1.0.5.tgz#96917d198fa21918cfc17475a3a1536190ee7aed"
stream-browserify@^2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/stream-browserify/-/stream-browserify-2.0.1.tgz#66266ee5f9bdb9940a4e4514cafb43bb71e5c9db"