mirror of
https://github.com/typicode/json-server.git
synced 2025-07-31 06:01:50 +08:00
Fix
This commit is contained in:
@ -1 +1,2 @@
|
|||||||
|
src/server/public
|
||||||
lib
|
lib
|
||||||
|
@ -9,6 +9,7 @@ module.exports = {
|
|||||||
semi: false,
|
semi: false,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
'prefer-template': "error"
|
||||||
},
|
},
|
||||||
env: { mocha: true },
|
env: { mocha: true }
|
||||||
}
|
}
|
||||||
|
@ -92,12 +92,6 @@
|
|||||||
"url": "https://github.com/typicode/json-server/issues"
|
"url": "https://github.com/typicode/json-server/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/typicode/json-server",
|
"homepage": "https://github.com/typicode/json-server",
|
||||||
"standard": {
|
|
||||||
"fix": true,
|
|
||||||
"env": {
|
|
||||||
"mocha": true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">= 4"
|
"node": ">= 4"
|
||||||
}
|
}
|
||||||
|
@ -18,20 +18,20 @@ function prettyPrint(argv, object, rules) {
|
|||||||
console.log()
|
console.log()
|
||||||
console.log(chalk.bold(' Resources'))
|
console.log(chalk.bold(' Resources'))
|
||||||
for (let prop in object) {
|
for (let prop in object) {
|
||||||
console.log(' ' + root + '/' + prop)
|
console.log(` ${root}/${prop}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rules) {
|
if (rules) {
|
||||||
console.log()
|
console.log()
|
||||||
console.log(chalk.bold(' Other routes'))
|
console.log(chalk.bold(' Other routes'))
|
||||||
for (var rule in rules) {
|
for (var rule in rules) {
|
||||||
console.log(' ' + rule + ' -> ' + rules[rule])
|
console.log(` ${rule} -> ${rules[rule]}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log()
|
console.log()
|
||||||
console.log(chalk.bold(' Home'))
|
console.log(chalk.bold(' Home'))
|
||||||
console.log(' ' + root)
|
console.log(` ${root}`)
|
||||||
console.log()
|
console.log()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,7 +172,7 @@ module.exports = function(argv) {
|
|||||||
process.stdin.setEncoding('utf8')
|
process.stdin.setEncoding('utf8')
|
||||||
process.stdin.on('data', chunk => {
|
process.stdin.on('data', chunk => {
|
||||||
if (chunk.trim().toLowerCase() === 's') {
|
if (chunk.trim().toLowerCase() === 's') {
|
||||||
const filename = 'db-' + Date.now() + '.json'
|
const filename = `db-${Date.now()}.json`
|
||||||
const file = path.join(argv.snapshots, filename)
|
const file = path.join(argv.snapshots, filename)
|
||||||
const state = app.db.getState()
|
const state = app.db.getState()
|
||||||
fs.writeFileSync(file, JSON.stringify(state, null, 2), 'utf-8')
|
fs.writeFileSync(file, JSON.stringify(state, null, 2), 'utf-8')
|
||||||
|
@ -36,6 +36,6 @@ module.exports = function(source, cb) {
|
|||||||
const data = low(source, { storage: fileAsync }).getState()
|
const data = low(source, { storage: fileAsync }).getState()
|
||||||
cb(null, data)
|
cb(null, data)
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Unsupported source ' + source)
|
throw new Error(`Unsupported source ${source}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,14 +19,14 @@ module.exports = routes => {
|
|||||||
// Rewrite target url using params
|
// Rewrite target url using params
|
||||||
let target = routes[route]
|
let target = routes[route]
|
||||||
for (let param in req.params) {
|
for (let param in req.params) {
|
||||||
target = target.replace(':' + param, req.params[param])
|
target = target.replace(`:${param}`, req.params[param])
|
||||||
}
|
}
|
||||||
req.url = target
|
req.url = target
|
||||||
req.query = updateQueryString(req.query, req.url)
|
req.query = updateQueryString(req.query, req.url)
|
||||||
next()
|
next()
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
router.all(route + '*', (req, res, next) => {
|
router.all(`${route}*`, (req, res, next) => {
|
||||||
// Rewrite url by replacing prefix
|
// Rewrite url by replacing prefix
|
||||||
req.url = req.url.replace(route, routes[route])
|
req.url = req.url.replace(route, routes[route])
|
||||||
req.query = updateQueryString(req.query, req.url)
|
req.query = updateQueryString(req.query, req.url)
|
||||||
|
@ -66,10 +66,10 @@ module.exports = (source, opts = { foreignKeySuffix: 'Id' }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const msg =
|
const msg =
|
||||||
`Type of "${key}" (${typeof value}) ` +
|
`Type of "${key}" (${typeof value}) ${_.isObject(source)
|
||||||
(_.isObject(source) ? '' : `in ${source}`) +
|
? ''
|
||||||
' is not supported. ' +
|
: `in ${source}`} is not supported. ` +
|
||||||
'Use objects or arrays of objects.'
|
`Use objects or arrays of objects.`
|
||||||
|
|
||||||
throw new Error(msg)
|
throw new Error(msg)
|
||||||
})
|
})
|
||||||
|
@ -161,7 +161,7 @@ module.exports = (db, name, opts) => {
|
|||||||
res.setHeader('X-Total-Count', chain.size())
|
res.setHeader('X-Total-Count', chain.size())
|
||||||
res.setHeader(
|
res.setHeader(
|
||||||
'Access-Control-Expose-Headers',
|
'Access-Control-Expose-Headers',
|
||||||
'X-Total-Count' + (_page ? ', Link' : '')
|
`X-Total-Count${_page ? ', Link' : ''}`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,29 +175,29 @@ module.exports = (db, name, opts) => {
|
|||||||
|
|
||||||
if (page.first) {
|
if (page.first) {
|
||||||
links.first = fullURL.replace(
|
links.first = fullURL.replace(
|
||||||
'page=' + page.current,
|
`page=${page.current}`,
|
||||||
'page=' + page.first
|
`page=${page.first}`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (page.prev) {
|
if (page.prev) {
|
||||||
links.prev = fullURL.replace(
|
links.prev = fullURL.replace(
|
||||||
'page=' + page.current,
|
`page=${page.current}`,
|
||||||
'page=' + page.prev
|
`page=${page.prev}`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (page.next) {
|
if (page.next) {
|
||||||
links.next = fullURL.replace(
|
links.next = fullURL.replace(
|
||||||
'page=' + page.current,
|
`page=${page.current}`,
|
||||||
'page=' + page.next
|
`page=${page.next}`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (page.last) {
|
if (page.last) {
|
||||||
links.last = fullURL.replace(
|
links.last = fullURL.replace(
|
||||||
'page=' + page.current,
|
`page=${page.current}`,
|
||||||
'page=' + page.last
|
`page=${page.last}`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user