Hi, when using webpack's HMR, and changing the server's port, it leaves the previous Koa server still in tact on another port.
How can I stop the Koa server mid-stage, allowing HMR to restart another one?
Is there a koa.close like there is a server.close?
this should do the trick:
var destroyable = require('server-destroy');
var http = require('http');
var server = http.createServer(app.callback());
server.listen();
destroyable(server);
// then
server.destroy();
for more questions like this, please post on stackoverflow because it's more about usage than bugs or improvements to koa.
@juliangruber 's solution totally works, but here is a simpler one.
const app = new Koa();
const _server = app.listen(3000); // start
_server.close(); // stop
this won't close when there are still open connections, the destroy method above really enforces the server to close, no matter what
Neither of these solutions work when using chokidar to reload a server.js on file changes.
Both works for me in an after hook in mocha unit tests
Most helpful comment
@juliangruber 's solution totally works, but here is a simpler one.