mirror of
https://github.com/typicode/json-server.git
synced 2025-07-27 20:23:34 +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",
|
"node-uuid": "^1.4.2",
|
||||||
"object-assign": "^4.0.1",
|
"object-assign": "^4.0.1",
|
||||||
"pluralize": "^1.1.2",
|
"pluralize": "^1.1.2",
|
||||||
|
"server-destroy": "^1.0.1",
|
||||||
"underscore-db": "^0.9.1",
|
"underscore-db": "^0.9.1",
|
||||||
"update-notifier": "^0.5.0",
|
"update-notifier": "^0.5.0",
|
||||||
"yargs": "^3.10.0"
|
"yargs": "^3.10.0"
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
var fs = require('fs')
|
var fs = require('fs')
|
||||||
var path = require('path')
|
var path = require('path')
|
||||||
var chalk = require('chalk')
|
var chalk = require('chalk')
|
||||||
|
var enableDestroy = require('server-destroy')
|
||||||
var is = require('./utils/is')
|
var is = require('./utils/is')
|
||||||
var load = require('./utils/load')
|
var load = require('./utils/load')
|
||||||
var watch = require('./watch')
|
var watch = require('./watch')
|
||||||
@ -111,6 +112,9 @@ module.exports = function (argv) {
|
|||||||
app = createApp(source, data, routes, argv)
|
app = createApp(source, data, routes, argv)
|
||||||
server = app.listen(argv.port, argv.host)
|
server = app.listen(argv.port, argv.host)
|
||||||
|
|
||||||
|
// Enhance with a destroy function
|
||||||
|
enableDestroy(server)
|
||||||
|
|
||||||
// Display server informations
|
// Display server informations
|
||||||
prettyPrint(argv, data, routes)
|
prettyPrint(argv, data, routes)
|
||||||
|
|
||||||
@ -143,7 +147,7 @@ module.exports = function (argv) {
|
|||||||
console.log()
|
console.log()
|
||||||
watch(argv, function (file) {
|
watch(argv, function (file) {
|
||||||
console.log(chalk.gray(' ' + file + ' has changed, reloading...'))
|
console.log(chalk.gray(' ' + file + ' has changed, reloading...'))
|
||||||
server && server.close()
|
server && server.destroy()
|
||||||
start()
|
start()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user