mirror of
https://github.com/typicode/json-server.git
synced 2025-07-27 04:02:38 +08:00
Fix #177 force closing all currently open connections when reloading server
This commit is contained in:
@ -22,6 +22,7 @@
|
||||
"node-uuid": "^1.4.2",
|
||||
"object-assign": "^4.0.1",
|
||||
"pluralize": "^1.1.2",
|
||||
"server-destroy": "^1.0.1",
|
||||
"underscore-db": "^0.9.1",
|
||||
"update-notifier": "^0.5.0",
|
||||
"yargs": "^3.10.0"
|
||||
|
@ -1,6 +1,7 @@
|
||||
var fs = require('fs')
|
||||
var path = require('path')
|
||||
var chalk = require('chalk')
|
||||
var enableDestroy = require('server-destroy')
|
||||
var is = require('./utils/is')
|
||||
var load = require('./utils/load')
|
||||
var watch = require('./watch')
|
||||
@ -111,6 +112,9 @@ module.exports = function (argv) {
|
||||
app = createApp(source, data, routes, argv)
|
||||
server = app.listen(argv.port, argv.host)
|
||||
|
||||
// Enhance with a destroy function
|
||||
enableDestroy(server)
|
||||
|
||||
// Display server informations
|
||||
prettyPrint(argv, data, routes)
|
||||
|
||||
@ -143,7 +147,7 @@ module.exports = function (argv) {
|
||||
console.log()
|
||||
watch(argv, function (file) {
|
||||
console.log(chalk.gray(' ' + file + ' has changed, reloading...'))
|
||||
server && server.close()
|
||||
server && server.destroy()
|
||||
start()
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user