Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
typicode committed Jul 2, 2017
1 parent 14de49f commit bd3fb1f
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 27 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
src/server/public
lib
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = {
semi: false,
},
],
'prefer-template': "error"
},
env: { mocha: true },
env: { mocha: true }
}
6 changes: 0 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,6 @@
"url": "https://github.com/typicode/json-server/issues"
},
"homepage": "https://github.com/typicode/json-server",
"standard": {
"fix": true,
"env": {
"mocha": true
}
},
"engines": {
"node": ">= 4"
}
Expand Down
8 changes: 4 additions & 4 deletions src/cli/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ function prettyPrint(argv, object, rules) {
console.log()
console.log(chalk.bold(' Resources'))
for (let prop in object) {
console.log(' ' + root + '/' + prop)
console.log(` ${root}/${prop}`)
}

if (rules) {
console.log()
console.log(chalk.bold(' Other routes'))
for (var rule in rules) {
console.log(' ' + rule + ' -> ' + rules[rule])
console.log(` ${rule} -> ${rules[rule]}`)
}
}

console.log()
console.log(chalk.bold(' Home'))
console.log(' ' + root)
console.log(` ${root}`)
console.log()
}

Expand Down Expand Up @@ -172,7 +172,7 @@ module.exports = function(argv) {
process.stdin.setEncoding('utf8')
process.stdin.on('data', chunk => {
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 state = app.db.getState()
fs.writeFileSync(file, JSON.stringify(state, null, 2), 'utf-8')
Expand Down
2 changes: 1 addition & 1 deletion src/cli/utils/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ module.exports = function(source, cb) {
const data = low(source, { storage: fileAsync }).getState()
cb(null, data)
} else {
throw new Error('Unsupported source ' + source)
throw new Error(`Unsupported source ${source}`)
}
}
4 changes: 2 additions & 2 deletions src/server/rewriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ module.exports = routes => {
// Rewrite target url using params
let target = routes[route]
for (let param in req.params) {
target = target.replace(':' + param, req.params[param])
target = target.replace(`:${param}`, req.params[param])
}
req.url = target
req.query = updateQueryString(req.query, req.url)
next()
})
} else {
router.all(route + '*', (req, res, next) => {
router.all(`${route}*`, (req, res, next) => {
// Rewrite url by replacing prefix
req.url = req.url.replace(route, routes[route])
req.query = updateQueryString(req.query, req.url)
Expand Down
8 changes: 4 additions & 4 deletions src/server/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ module.exports = (source, opts = { foreignKeySuffix: 'Id' }) => {
}

const msg =
`Type of "${key}" (${typeof value}) ` +
(_.isObject(source) ? '' : `in ${source}`) +
' is not supported. ' +
'Use objects or arrays of objects.'
`Type of "${key}" (${typeof value}) ${_.isObject(source)
? ''
: `in ${source}`} is not supported. ` +
`Use objects or arrays of objects.`

throw new Error(msg)
})
Expand Down
18 changes: 9 additions & 9 deletions src/server/router/plural.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ module.exports = (db, name, opts) => {
res.setHeader('X-Total-Count', chain.size())
res.setHeader(
'Access-Control-Expose-Headers',
'X-Total-Count' + (_page ? ', Link' : '')
`X-Total-Count${_page ? ', Link' : ''}`
)
}

Expand All @@ -175,29 +175,29 @@ module.exports = (db, name, opts) => {

if (page.first) {
links.first = fullURL.replace(
'page=' + page.current,
'page=' + page.first
`page=${page.current}`,
`page=${page.first}`
)
}

if (page.prev) {
links.prev = fullURL.replace(
'page=' + page.current,
'page=' + page.prev
`page=${page.current}`,
`page=${page.prev}`
)
}

if (page.next) {
links.next = fullURL.replace(
'page=' + page.current,
'page=' + page.next
`page=${page.current}`,
`page=${page.next}`
)
}

if (page.last) {
links.last = fullURL.replace(
'page=' + page.current,
'page=' + page.last
`page=${page.current}`,
`page=${page.last}`
)
}

Expand Down

0 comments on commit bd3fb1f

Please sign in to comment.