json-server 0.12.2 → 0.14.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/.babelrc +8 -6
- package/.eslintrc.js +2 -2
- package/CHANGELOG.md +18 -0
- package/README.md +26 -21
- package/{lib/server/public → dist}/favicon.ico +0 -0
- package/{lib/server/public → dist}/index.html +3 -11
- package/dist/main.css +675 -0
- package/dist/main.js +1 -0
- package/lib/cli/bin.js +4 -1
- package/lib/cli/index.js +13 -8
- package/lib/cli/run.js +98 -109
- package/lib/cli/utils/is.js +3 -4
- package/lib/cli/utils/load.js +71 -38
- package/lib/front/index.js +67 -0
- package/lib/server/body-parser.js +8 -3
- package/lib/server/defaults.js +44 -37
- package/lib/server/index.js +3 -5
- package/lib/server/mixins.js +37 -26
- package/lib/server/rewriter.js +7 -9
- package/lib/server/router/delay.js +4 -3
- package/lib/server/router/get-full-url.js +3 -4
- package/lib/server/router/index.js +59 -59
- package/lib/server/router/nested.js +13 -12
- package/lib/server/router/plural.js +134 -110
- package/lib/server/router/singular.js +35 -17
- package/lib/server/router/validate-data.js +4 -4
- package/lib/server/router/write.js +1 -1
- package/lib/server/utils.js +1 -1
- package/package.json +79 -51
- package/webpack.config.js +21 -0
- package/bin/index.js +0 -3
- package/lib/cli/example.json +0 -9
- package/lib/server/public/images/json.png +0 -0
- package/lib/server/public/main.js +0 -39
- package/lib/server/public/style.css +0 -73
package/.babelrc
CHANGED
package/.eslintrc.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
module.exports = {
|
|
2
|
-
extends: ['standard', 'prettier'],
|
|
2
|
+
extends: ['standard', 'standard-preact', 'prettier'],
|
|
3
3
|
plugins: ['prettier'],
|
|
4
4
|
rules: {
|
|
5
5
|
'prettier/prettier': [
|
|
@@ -10,5 +10,5 @@ module.exports = {
|
|
|
10
10
|
},
|
|
11
11
|
]
|
|
12
12
|
},
|
|
13
|
-
env: {
|
|
13
|
+
env: { jest: true }
|
|
14
14
|
}
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 0.14.2 - 2018-12-26
|
|
4
|
+
|
|
5
|
+
* Fix `db.getState is not a function`
|
|
6
|
+
|
|
7
|
+
## 0.14.1 - 2018-12-25
|
|
8
|
+
|
|
9
|
+
* Show error message if port is already used
|
|
10
|
+
* Upgrade to [lowdb](https://github.com/typicode/lowdb) `1.0`
|
|
11
|
+
|
|
12
|
+
## 0.14.0 - 2018-06-09
|
|
13
|
+
|
|
14
|
+
* Listen to `localhost` by default, instead of `0.0.0.0`
|
|
15
|
+
|
|
16
|
+
## 0.13.0 - 2018-05-30
|
|
17
|
+
|
|
18
|
+
* Bundle all index page assets so that you access it without network connection
|
|
19
|
+
* Drop Node 4 support
|
|
20
|
+
|
|
3
21
|
## 0.12.2 - 2018-04-26
|
|
4
22
|
|
|
5
23
|
* Add `_delay` query parameter
|
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# JSON Server [](https://travis-ci.org/typicode/json-server) [](http://badge.fury.io/js/json-server)
|
|
1
|
+
# JSON Server [](https://travis-ci.org/typicode/json-server) [](http://badge.fury.io/js/json-server)
|
|
2
2
|
|
|
3
3
|
Get a full fake REST API with __zero coding__ in __less than 30 seconds__ (seriously)
|
|
4
4
|
|
|
@@ -10,18 +10,22 @@ Created with <3 for front-end developers who need a quick back-end for prototypi
|
|
|
10
10
|
See also:
|
|
11
11
|
* :dog: [husky - Git hooks made easy](https://github.com/typicode/husky)
|
|
12
12
|
* :hotel: [hotel - developer tool with local .localhost domain and https out of the box](https://github.com/typicode/hotel)
|
|
13
|
-
*
|
|
14
|
-
* :heartpulse: [Patreon page - if you want to support JSON Server or my other projects](https://www.patreon.com/typicode)
|
|
13
|
+
* ⚛️ 🔧 [react-lodash - lodash as React components](https://github.com/typicode/react-lodash)
|
|
15
14
|
|
|
16
|
-
|
|
15
|
+
<a href="https://www.patreon.com/typicode">
|
|
16
|
+
<img src="https://c5.patreon.com/external/logo/become_a_patron_button@2x.png" width="160">
|
|
17
|
+
</a>
|
|
18
|
+
|
|
19
|
+
## Sponsors
|
|
20
|
+
|
|
21
|
+
__[[Become a sponsor and have your company logo here]](https://patreon.com/typicode)__
|
|
17
22
|
|
|
18
|
-
|
|
23
|
+
## Table of contents
|
|
19
24
|
|
|
20
25
|
<!-- toc -->
|
|
21
26
|
|
|
22
27
|
- [Sponsorship](#sponsorship)
|
|
23
|
-
- [
|
|
24
|
-
- [Install](#install)
|
|
28
|
+
- [Getting started](#getting-started)
|
|
25
29
|
- [Routes](#routes)
|
|
26
30
|
* [Plural routes](#plural-routes)
|
|
27
31
|
* [Singular routes](#singular-routes)
|
|
@@ -61,11 +65,15 @@ See also:
|
|
|
61
65
|
|
|
62
66
|
<!-- tocstop -->
|
|
63
67
|
|
|
64
|
-
|
|
68
|
+
## Getting started
|
|
69
|
+
|
|
70
|
+
Install JSON Server
|
|
65
71
|
|
|
66
|
-
|
|
72
|
+
```
|
|
73
|
+
npm install -g json-server
|
|
74
|
+
```
|
|
67
75
|
|
|
68
|
-
Create a `db.json` file
|
|
76
|
+
Create a `db.json` file with some data
|
|
69
77
|
|
|
70
78
|
```json
|
|
71
79
|
{
|
|
@@ -82,7 +90,7 @@ Create a `db.json` file
|
|
|
82
90
|
Start JSON Server
|
|
83
91
|
|
|
84
92
|
```bash
|
|
85
|
-
|
|
93
|
+
json-server --watch db.json
|
|
86
94
|
```
|
|
87
95
|
|
|
88
96
|
Now if you go to [http://localhost:3000/posts/1](http://localhost:3000/posts/1), you'll get
|
|
@@ -95,15 +103,9 @@ Also when doing requests, it's good to know that:
|
|
|
95
103
|
|
|
96
104
|
- If you make POST, PUT, PATCH or DELETE requests, changes will be automatically and safely saved to `db.json` using [lowdb](https://github.com/typicode/lowdb).
|
|
97
105
|
- Your request body JSON should be object enclosed, just like the GET output. (for example `{"name": "Foobar"}`)
|
|
98
|
-
- Id values are not mutable. Any `id` value in the body of your PUT or PATCH request
|
|
106
|
+
- Id values are not mutable. Any `id` value in the body of your PUT or PATCH request will be ignored. Only a value set in a POST request will be respected, but only if not already taken.
|
|
99
107
|
- A POST, PUT or PATCH request should include a `Content-Type: application/json` header to use the JSON in the request body. Otherwise it will result in a 200 OK but without changes being made to the data.
|
|
100
108
|
|
|
101
|
-
## Install
|
|
102
|
-
|
|
103
|
-
```bash
|
|
104
|
-
$ npm install -g json-server
|
|
105
|
-
```
|
|
106
|
-
|
|
107
109
|
## Routes
|
|
108
110
|
|
|
109
111
|
Based on the previous `db.json` file, here are all the default routes. You can also add [other routes](#add-custom-routes) using `--routes`.
|
|
@@ -306,7 +308,7 @@ __Tip__ use modules like [Faker](https://github.com/Marak/faker.js), [Casual](ht
|
|
|
306
308
|
|
|
307
309
|
### HTTPS
|
|
308
310
|
|
|
309
|
-
There
|
|
311
|
+
There are many ways to set up SSL in development. One simple way is to use [hotel](https://github.com/typicode/hotel).
|
|
310
312
|
|
|
311
313
|
### Add custom routes
|
|
312
314
|
|
|
@@ -362,7 +364,7 @@ json-server [options] <source>
|
|
|
362
364
|
Options:
|
|
363
365
|
--config, -c Path to config file [default: "json-server.json"]
|
|
364
366
|
--port, -p Set port [default: 3000]
|
|
365
|
-
--host, -H Set host
|
|
367
|
+
--host, -H Set host [default: "localhost"]
|
|
366
368
|
--watch, -w Watch file(s) [boolean]
|
|
367
369
|
--routes, -r Path to routes file
|
|
368
370
|
--middlewares, -m Paths to middleware files [array]
|
|
@@ -575,6 +577,7 @@ You can deploy JSON Server. For example, [JSONPlaceholder](http://jsonplaceholde
|
|
|
575
577
|
* [Fast prototyping using Restangular and Json-server](http://glebbahmutov.com/blog/fast-prototyping-using-restangular-and-json-server/)
|
|
576
578
|
* [Create a Mock REST API in Seconds for Prototyping your Frontend](https://coligo.io/create-mock-rest-api-with-json-server/)
|
|
577
579
|
* [No API? No Problem! Rapid Development via Mock APIs](https://medium.com/@housecor/rapid-development-via-mock-apis-e559087be066#.93d7w8oro)
|
|
580
|
+
* [Zero Code REST With json-server](https://dzone.com/articles/zero-code-rest-with-json-server)
|
|
578
581
|
|
|
579
582
|
### Third-party tools
|
|
580
583
|
|
|
@@ -586,4 +589,6 @@ You can deploy JSON Server. For example, [JSONPlaceholder](http://jsonplaceholde
|
|
|
586
589
|
|
|
587
590
|
## License
|
|
588
591
|
|
|
589
|
-
MIT
|
|
592
|
+
MIT
|
|
593
|
+
|
|
594
|
+
[Patreon](https://www.patreon.com/typicode) - [Supporters](https://thanks.typicode.com) ✨
|
|
File without changes
|
|
@@ -2,11 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
<head>
|
|
4
4
|
<title>JSON Server</title>
|
|
5
|
-
|
|
6
|
-
<link rel="stylesheet" href="//cdn.rawgit.com/necolas/normalize.css/master/normalize.css">
|
|
7
|
-
<link rel="stylesheet" href="//cdn.rawgit.com/milligram/milligram/master/dist/milligram.min.css">
|
|
8
|
-
<link rel="stylesheet" href="style.css">
|
|
9
|
-
</head>
|
|
5
|
+
<link rel="shortcut icon" href="favicon.ico"><link href="main.css" rel="stylesheet"></head>
|
|
10
6
|
|
|
11
7
|
<body>
|
|
12
8
|
<header>
|
|
@@ -53,9 +49,5 @@
|
|
|
53
49
|
</p>
|
|
54
50
|
</div>
|
|
55
51
|
</footer>
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
<script src="main.js"></script>
|
|
59
|
-
</body>
|
|
60
|
-
|
|
61
|
-
</html>
|
|
52
|
+
<script type="text/javascript" src="main.js"></script></body>
|
|
53
|
+
</html>
|