json-server 0.17.0 → 0.17.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -10
- package/lib/cli/index.js +0 -6
- package/lib/cli/utils/is.js +1 -1
- package/lib/server/router/validate-data.js +2 -1
- package/package.json +2 -2
- package/public/script.js +4 -4
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ Created with <3 for front-end developers who need a quick back-end for prototypi
|
|
|
11
11
|
See also:
|
|
12
12
|
* :dog: [husky - Git hooks made easy](https://github.com/typicode/husky)
|
|
13
13
|
* :owl: [lowdb - local JSON database](https://github.com/typicode/lowdb)
|
|
14
|
-
*
|
|
14
|
+
* ✅ [xv - a beautifully simple and capable test runner](https://github.com/typicode/xv)
|
|
15
15
|
|
|
16
16
|
<p> </p>
|
|
17
17
|
|
|
@@ -36,16 +36,16 @@ See also:
|
|
|
36
36
|
<p> </p>
|
|
37
37
|
|
|
38
38
|
<p align="center">
|
|
39
|
-
<a href="https://
|
|
40
|
-
<img src="https://jsonplaceholder.typicode.com/
|
|
39
|
+
<a href="https://megafamous.com/buy-instagram-followers" target="_blank">
|
|
40
|
+
<img src="https://jsonplaceholder.typicode.com/megafamous.png" height="70px">
|
|
41
41
|
</a>
|
|
42
42
|
</p>
|
|
43
43
|
|
|
44
44
|
<p> </p>
|
|
45
45
|
|
|
46
46
|
<p align="center">
|
|
47
|
-
<a href="
|
|
48
|
-
<img src="https://jsonplaceholder.typicode.com/
|
|
47
|
+
<a href="http://asocks.com/c/TFw5bz" target="_blank">
|
|
48
|
+
<img src="https://jsonplaceholder.typicode.com/asocks.png" height="70px">
|
|
49
49
|
</a>
|
|
50
50
|
</p>
|
|
51
51
|
|
|
@@ -53,11 +53,15 @@ See also:
|
|
|
53
53
|
|
|
54
54
|
<p> </p>
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
<h2 align="center">Silver sponsors 🥈</h2>
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
<p> </p>
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
<p align="center">
|
|
61
|
+
<a href="https://cased.com" target="_blank">
|
|
62
|
+
<img src="https://user-images.githubusercontent.com/5502029/194441951-b7dca49d-efd6-496d-900b-288004717f11.png" height="55px">
|
|
63
|
+
</a>
|
|
64
|
+
</p>
|
|
61
65
|
|
|
62
66
|
<p> </p>
|
|
63
67
|
|
|
@@ -352,7 +356,7 @@ module.exports = () => {
|
|
|
352
356
|
$ json-server index.js
|
|
353
357
|
```
|
|
354
358
|
|
|
355
|
-
__Tip__ use modules like [Faker](https://github.com/
|
|
359
|
+
__Tip__ use modules like [Faker](https://github.com/faker-js/faker), [Casual](https://github.com/boo1ean/casual), [Chance](https://github.com/victorquinn/chancejs) or [JSON Schema Faker](https://github.com/json-schema-faker/json-schema-faker).
|
|
356
360
|
|
|
357
361
|
### HTTPS
|
|
358
362
|
|
|
@@ -482,6 +486,8 @@ const router = jsonServer.router(path.join(__dirname, 'db.json'))
|
|
|
482
486
|
|
|
483
487
|
For an in-memory database, simply pass an object to `jsonServer.router()`.
|
|
484
488
|
|
|
489
|
+
To add custom options (eg. `foreginKeySuffix`) pass in an object as the second argument to `jsonServer.router('db.json', { foreginKeySuffix: '_id' })`.
|
|
490
|
+
|
|
485
491
|
Please note also that `jsonServer.router()` can be used in existing Express projects.
|
|
486
492
|
|
|
487
493
|
#### Custom routes example
|
|
@@ -603,10 +609,12 @@ Returns middlewares used by JSON Server.
|
|
|
603
609
|
* `noCors` disable CORS (default: false)
|
|
604
610
|
* `readOnly` accept only GET requests (default: false)
|
|
605
611
|
|
|
606
|
-
__`jsonServer.router([path|object])`__
|
|
612
|
+
__`jsonServer.router([path|object], [options])`__
|
|
607
613
|
|
|
608
614
|
Returns JSON Server router.
|
|
609
615
|
|
|
616
|
+
* options (see [CLI usage](#cli-usage))
|
|
617
|
+
|
|
610
618
|
### Deployment
|
|
611
619
|
|
|
612
620
|
You can deploy JSON Server. For example, [JSONPlaceholder](http://jsonplaceholder.typicode.com) is an online fake API powered by JSON Server and running on Heroku.
|
package/lib/cli/index.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
const updateNotifier = require('update-notifier');
|
|
4
|
-
|
|
5
3
|
const yargs = require('yargs');
|
|
6
4
|
|
|
7
5
|
const run = require('./run');
|
|
@@ -9,10 +7,6 @@ const run = require('./run');
|
|
|
9
7
|
const pkg = require('../../package.json');
|
|
10
8
|
|
|
11
9
|
module.exports = function () {
|
|
12
|
-
updateNotifier({
|
|
13
|
-
pkg
|
|
14
|
-
}).notify();
|
|
15
|
-
|
|
16
10
|
const argv = yargs.config('config').usage('$0 [options] <source>').options({
|
|
17
11
|
port: {
|
|
18
12
|
alias: 'p',
|
package/lib/cli/utils/is.js
CHANGED
|
@@ -13,6 +13,7 @@ module.exports = obj => {
|
|
|
13
13
|
if (_.isPlainObject(obj)) {
|
|
14
14
|
Object.keys(obj).forEach(validateKey);
|
|
15
15
|
} else {
|
|
16
|
-
throw new Error(`Data must be an object. Found ${
|
|
16
|
+
throw new Error(`Data must be an object. Found ${Array.isArray(obj) ? 'array' : typeof obj}
|
|
17
|
+
'See https://github.com/typicode/json-server for example.`);
|
|
17
18
|
}
|
|
18
19
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "json-server",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.2",
|
|
4
4
|
"description": "Get a full fake REST API with zero coding in less than 30 seconds",
|
|
5
5
|
"main": "./lib/server/index.js",
|
|
6
6
|
"bin": "./lib/cli/bin.js",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"please-upgrade-node": "^3.2.0",
|
|
39
39
|
"pluralize": "^8.0.0",
|
|
40
40
|
"server-destroy": "^1.0.1",
|
|
41
|
-
"
|
|
41
|
+
"standard": "^17.0.0",
|
|
42
42
|
"yargs": "^17.0.1"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
package/public/script.js
CHANGED
|
@@ -15,7 +15,7 @@ function ResourceList({ db }) {
|
|
|
15
15
|
ResourceItem({
|
|
16
16
|
name,
|
|
17
17
|
length: Array.isArray(db[name]) && db[name].length,
|
|
18
|
-
})
|
|
18
|
+
}),
|
|
19
19
|
)
|
|
20
20
|
.join('')}
|
|
21
21
|
</ul>
|
|
@@ -40,7 +40,7 @@ window
|
|
|
40
40
|
.then((response) => response.json())
|
|
41
41
|
.then(
|
|
42
42
|
(db) =>
|
|
43
|
-
(document.getElementById('resources').innerHTML = ResourcesBlock({ db }))
|
|
43
|
+
(document.getElementById('resources').innerHTML = ResourcesBlock({ db })),
|
|
44
44
|
)
|
|
45
45
|
|
|
46
46
|
function CustomRoutesBlock({ customRoutes }) {
|
|
@@ -56,7 +56,7 @@ function CustomRoutesBlock({ customRoutes }) {
|
|
|
56
56
|
`<tr>
|
|
57
57
|
<td>${rule}</td>
|
|
58
58
|
<td><code>⇢</code> ${customRoutes[rule]}</td>
|
|
59
|
-
</tr
|
|
59
|
+
</tr>`,
|
|
60
60
|
)
|
|
61
61
|
.join('')}
|
|
62
62
|
</table>
|
|
@@ -72,5 +72,5 @@ window
|
|
|
72
72
|
(customRoutes) =>
|
|
73
73
|
(document.getElementById('custom-routes').innerHTML = CustomRoutesBlock({
|
|
74
74
|
customRoutes,
|
|
75
|
-
}))
|
|
75
|
+
})),
|
|
76
76
|
)
|