8000 Fix · JavaScriptExpert/json-server@bd3fb1f · GitHub
[go: up one dir, main page]

Skip to content

Commit bd3fb1f

Browse files
committed
Fix
1 parent 14de49f commit bd3fb1f

File tree

8 files changed

+23
-27
lines changed

8 files changed

+23
-27
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
src/server/public
12
lib

.eslintrc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module.exports = {
99
semi: false,
1010
},
1111
],
12+
'prefer-template': "error"
1213
},
13-
env: { mocha: true },
14+
env: { mocha: true }
1415
}

package.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,6 @@
9292
"url": "https://github.com/typicode/json-server/issues"
9393
},
9494
"homepage": "https://github.com/typicode/json-server",
95-
"standard": {
96-
"fix": true,
97-
"env": {
98-
"mocha": true
99-
}
100-
},
10195
"engines": {
10296
"node": ">= 4"
10397
}

src/cli/run.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,20 @@ function prettyPrint(argv, object, rules) {
1818
console.log()
1919
console.log(chalk.bold(' Resources'))
2020
for (let prop in object) {
21-
console.log(' ' + root + '/' + prop)
21+
console.log(` ${root}/${prop}`)
2222
}
2323

2424
if (rules) {
2525
console.log()
2626
console.log(chalk.bold(' Other routes'))
2727
for (var rule in rules) {
28-
console.log(' ' + rule + ' -> ' + rules[rule])
28+
console.log(` ${rule} -> ${rules[rule]}`)
2929
}
3030
}
3131

3232
console.log()
3333
console.log(chalk.bold(' Home'))
34-
console.log(' ' + root)
34+
console.log(` ${root}`)
3535
console.log()
3636
}
3737

@@ -172,7 +172,7 @@ module.exports = function(argv) {
172172
process.stdin.setEncoding('utf8')
173173
process.stdin.on('data', chunk => {
174174
if (chunk.trim().toLowerCase() === 's') {
175-
const filename = 'db-' + Date.now() + '.json'
175+
const filename = `db-${Date.now()}.json`
176176
const file = path.join(argv.snapshots, filename)
177177
const state = app.db.getState()
178178
fs.writeFileSync(file, JSON.stringify(state, null, 2), 'utf-8')

src/cli/utils/load.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ module.exports = function(source, cb) {
3636
const data = low(source, { storage: fileAsync }).getState()
3737
cb(null, data)
3838
} else {
39-
throw new Error('Unsupported source ' + source)
39+
throw new Error(`Unsupported source ${source}`)
4040
}
4141
}

src/server/rewriter.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ module.exports = routes => {
1919
// Rewrite target url using params
2020
let target = routes[route]
2121
for (let param in req.params) {
22-
target = target.replace(':' + param, req.params[param])
22+
target = target.replace(`:${param}`, req.params[param])
2323
}
2424
req.url = target
2525
req.query = updateQueryString(req.query, req.url)
2626
next()
2727
})
2828
} else {
29-
router.all(route + '*', (req, res, next) => {
29+
router.all(`${route}*`, (req, res, next) => {
3030
// Rewrite url by replacing prefix
3131
req.url = req.url.replace(route, routes[route])
3232
req.query = updateQueryString(req.query, req.url)

src/server/router/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ module.exports = (source, opts = { foreignKeySuffix: 'Id' }) => {
6666
}
6767

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

7474
throw new Error(msg)
7575
})

src/server/router/plural.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ module.exports = (db, name, opts) => {
161161
res.setHeader('X-Total-Count', chain.size())
162162
res.setHeader(
163163
'Access-Control-Expose-Headers',
164-
'X-Total-Count' + (_page ? ', Link' : '')
164+
`X-Total-Count${_page ? ', Link' : ''}`
165165
)
166166
}
167167

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

176176
if (page.first) {
177177
links.first = fullURL.replace(
178-
'page=' + page.current,
179-
'page=' + page.first
178+
`page=${page.current}`,
179+
`page=${page.first}`
180180
)
181181
}
182182

183183
if (page.prev) {
184184
links.prev = fullURL.replace(
185-
'page=' + page.current,
186-
'page=' + page.prev
185+
`page=${page.current}`,
186+
`page=${page.prev}`
187187
)
188188
}
189189

190190
if (page.next) {
191191
links.next = fullURL.replace(
192-
'page=' + page.current,
193-
'page=' + page.next
192+
`page=${page.current}`,
193+
`page=${page.next}`
194194
)
195195
}
196196

197197
if (page.last) {
198198
links.last = fullURL.replace(
199-
'page=' + page.current,
200-
'page=' + page.last
199+
`page=${page.current}`,
200+
`page=${page.last}`
201201
)
202202
}
203203

0 commit comments

Comments
 (0)
0