mirror of
https://github.com/typicode/json-server.git
synced 2025-08-01 06:34:02 +08:00
Make router accept file path again
This commit is contained in:
@ -4,6 +4,7 @@ const _ = require('lodash')
|
|||||||
const lodashId = require('lodash-id')
|
const lodashId = require('lodash-id')
|
||||||
const low = require('lowdb')
|
const low = require('lowdb')
|
||||||
const Memory = require('lowdb/adapters/Memory')
|
const Memory = require('lowdb/adapters/Memory')
|
||||||
|
const FileAsync = require('lowdb/adapters/FileAsync')
|
||||||
const bodyParser = require('../body-parser')
|
const bodyParser = require('../body-parser')
|
||||||
const validateData = require('./validate-data')
|
const validateData = require('./validate-data')
|
||||||
const plural = require('./plural')
|
const plural = require('./plural')
|
||||||
@ -12,8 +13,9 @@ const singular = require('./singular')
|
|||||||
const mixins = require('../mixins')
|
const mixins = require('../mixins')
|
||||||
|
|
||||||
module.exports = (db, opts = { foreignKeySuffix: 'Id' }) => {
|
module.exports = (db, opts = { foreignKeySuffix: 'Id' }) => {
|
||||||
var isDB = _.has(db, '__chain__') && _.has(db, '__wrapped__')
|
if (typeof db === 'string') {
|
||||||
if (!isDB) {
|
db = low(new FileAsync(db))
|
||||||
|
} else if (!_.has(db, '__chain__') || !_.has(db, '__wrapped__')) {
|
||||||
db = low(new Memory()).setState(db)
|
db = low(new Memory()).setState(db)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user