mirror of
https://github.com/typicode/json-server.git
synced 2025-07-29 21:23:41 +08:00
style update to standard v7
This commit is contained in:
@ -4,7 +4,6 @@ var run = require('./run')
|
||||
var pkg = require('../../package.json')
|
||||
|
||||
module.exports = function () {
|
||||
|
||||
updateNotifier({ pkg: pkg }).notify()
|
||||
|
||||
var argv = yargs
|
||||
|
@ -74,7 +74,6 @@ function createApp (source, object, routes, argv) {
|
||||
}
|
||||
|
||||
module.exports = function (argv) {
|
||||
|
||||
var source = argv._[0]
|
||||
var app
|
||||
var server
|
||||
@ -98,7 +97,6 @@ module.exports = function (argv) {
|
||||
|
||||
// Load JSON, JS or HTTP database
|
||||
load(source, function (err, data) {
|
||||
|
||||
if (err) throw err
|
||||
|
||||
// Load additional routes
|
||||
@ -125,7 +123,6 @@ module.exports = function (argv) {
|
||||
|
||||
// Start server
|
||||
start(function () {
|
||||
|
||||
// Snapshot
|
||||
console.log(
|
||||
chalk.gray(' Type s + enter at any time to create a snapshot of the database')
|
||||
@ -162,7 +159,6 @@ module.exports = function (argv) {
|
||||
.on('change', function (file) {
|
||||
if (file === source) {
|
||||
if (is.JSON(file)) {
|
||||
console.log(file, fs.readFileSync(file))
|
||||
var obj = JSON.parse(fs.readFileSync(file))
|
||||
// Compare .json file content with in memory database
|
||||
var isDatabaseDifferent = !_.eq(obj, app.db.getState())
|
||||
|
@ -8,14 +8,11 @@ module.exports = function (source, cb) {
|
||||
var data
|
||||
|
||||
if (is.URL(source)) {
|
||||
|
||||
request({ url: source, json: true }, function (err, response) {
|
||||
if (err) return cb(err)
|
||||
cb(null, response.body)
|
||||
})
|
||||
|
||||
} else if (is.JS(source)) {
|
||||
|
||||
var filename = path.resolve(source)
|
||||
delete require.cache[filename]
|
||||
var dataFn = require(filename)
|
||||
@ -26,15 +23,10 @@ module.exports = function (source, cb) {
|
||||
|
||||
data = dataFn()
|
||||
cb(null, data)
|
||||
|
||||
} else if (is.JSON(source)) {
|
||||
|
||||
data = low(source, { storage: fileAsync }).getState()
|
||||
cb(null, data)
|
||||
|
||||
} else {
|
||||
|
||||
throw new Error('Unsupported source ' + source)
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user