Skip to content

Commit 7cf8584

Browse files
committed
Merge branch 'master' of https://github.com/zhangbg/json-server into zhangbg-master
2 parents 760c37d + 485378d commit 7cf8584

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/cli/run.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,24 +190,29 @@ module.exports = function (argv) {
190190
// Since lowdb uses atomic writing, directory is watched instead of file
191191
const watchedDir = path.dirname(source)
192192
fs.watch(watchedDir, (event, file) => {
193+
<<<<<<< HEAD
193194
// https://github.com/typicode/json-server/issues/420
194195
// file can be null
195196
if (file) {
196197
const watchedFile = path.resolve(watchedDir, file)
197198
if (watchedFile === path.resolve(source)) {
198199
if (is.JSON(watchedFile)) {
199-
var obj = JSON.parse(fs.readFileSync(watchedFile))
200+
var obj
201+
try {
202+
obj = JSON.parse(fs.readFileSync(watchedFile))
203+
} catch (e) {
204+
console.log('Error reading JSON file');
205+
console.dir(e);
206+
return;
207+
}
208+
200209
// Compare .json file content with in memory database
201210
var isDatabaseDifferent = !_.isEqual(obj, app.db.getState())
202211
if (isDatabaseDifferent) {
203212
console.log(chalk.gray(` ${source} has changed, reloading...`))
204213
server && server.destroy()
205214
start()
206215
}
207-
} else {
208-
console.log(chalk.gray(` ${source} has changed, reloading...`))
209-
server && server.destroy()
210-
start()
211216
}
212217
}
213218
}

0 commit comments

Comments
 (0)