json-server 0.14.2 → 0.16.1
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 +1 -1
- package/.eslintrc.js +1 -1
- package/.github/FUNDING.yml +2 -0
- package/.github/workflows/main.yaml +31 -0
- package/.travis.yml +3 -1
- package/CHANGELOG.md +8 -0
- package/README.md +29 -10
- package/appveyor.yml +1 -1
- package/lib/cli/run.js +5 -3
- package/lib/front/index.js +54 -50
- package/lib/front/script.js +71 -0
- package/lib/server/defaults.js +2 -4
- package/lib/server/mixins.js +4 -5
- package/lib/server/router/index.js +6 -4
- package/lib/server/router/plural.js +16 -14
- package/lib/server/router/singular.js +4 -2
- package/package.json +38 -64
- package/postinstall.js +10 -0
- package/{dist → public}/favicon.ico +0 -0
- package/public/index.html +85 -0
- package/public/script.js +76 -0
- package/public/style.css +113 -0
- package/dist/index.html +0 -53
- package/dist/main.css +0 -675
- package/dist/main.js +0 -1
- package/webpack.config.js +0 -21
package/package.json
CHANGED
|
@@ -1,94 +1,68 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "json-server",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.16.1",
|
|
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",
|
|
7
|
-
"directories": {
|
|
8
|
-
"test": "test"
|
|
9
|
-
},
|
|
10
7
|
"scripts": {
|
|
11
8
|
"test": "npm run build && cross-env NODE_ENV=test jest && npm run lint",
|
|
12
|
-
"start": "
|
|
13
|
-
"start:babel-node": "babel-node src/cli/bin db.json -r routes.json",
|
|
14
|
-
"start:webpack": "webpack -d --watch",
|
|
9
|
+
"start": "babel-node -- src/cli/bin db.json -r routes.json",
|
|
15
10
|
"lint": "eslint . --ignore-path .gitignore",
|
|
16
11
|
"fix": "npm run lint -- --fix",
|
|
17
|
-
"build": "babel src -d lib
|
|
12
|
+
"build": "babel src -d lib",
|
|
18
13
|
"toc": "markdown-toc -i README.md",
|
|
14
|
+
"postversion": "git push && git push --tags",
|
|
19
15
|
"prepublishOnly": "npm test && npm run build && pkg-ok"
|
|
20
16
|
},
|
|
21
17
|
"dependencies": {
|
|
22
|
-
"body-parser": "^1.
|
|
23
|
-
"chalk": "^
|
|
24
|
-
"compression": "^1.7.
|
|
18
|
+
"body-parser": "^1.19.0",
|
|
19
|
+
"chalk": "^3.0.0",
|
|
20
|
+
"compression": "^1.7.4",
|
|
25
21
|
"connect-pause": "^0.1.1",
|
|
26
22
|
"cors": "^2.8.5",
|
|
27
|
-
"errorhandler": "^1.
|
|
28
|
-
"express": "^4.
|
|
23
|
+
"errorhandler": "^1.5.1",
|
|
24
|
+
"express": "^4.17.1",
|
|
29
25
|
"express-urlrewrite": "^1.2.0",
|
|
30
26
|
"json-parse-helpfulerror": "^1.0.3",
|
|
31
|
-
"lodash": "^4.17.
|
|
27
|
+
"lodash": "^4.17.15",
|
|
32
28
|
"lodash-id": "^0.14.0",
|
|
33
29
|
"lowdb": "^1.0.0",
|
|
34
30
|
"method-override": "^3.0.0",
|
|
35
31
|
"morgan": "^1.9.1",
|
|
36
|
-
"nanoid": "^2.
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"request": "^2.88.0",
|
|
32
|
+
"nanoid": "^2.1.11",
|
|
33
|
+
"please-upgrade-node": "^3.2.0",
|
|
34
|
+
"pluralize": "^8.0.0",
|
|
35
|
+
"request": "^2.88.2",
|
|
41
36
|
"server-destroy": "^1.0.1",
|
|
42
|
-
"update-notifier": "^
|
|
43
|
-
"yargs": "^
|
|
37
|
+
"update-notifier": "^4.0.0",
|
|
38
|
+
"yargs": "^15.1.0"
|
|
44
39
|
},
|
|
45
40
|
"devDependencies": {
|
|
46
|
-
"@babel/cli": "^7.
|
|
47
|
-
"@babel/core": "^7.
|
|
48
|
-
"@babel/node": "^7.
|
|
49
|
-
"@babel/
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"css-loader": "^1.0.1",
|
|
62
|
-
"eslint": "^5.11.0",
|
|
63
|
-
"eslint-config-prettier": "^3.3.0",
|
|
64
|
-
"eslint-config-standard": "^12.0.0",
|
|
65
|
-
"eslint-config-standard-preact": "^1.1.6",
|
|
66
|
-
"eslint-plugin-import": "^2.14.0",
|
|
67
|
-
"eslint-plugin-node": "^8.0.0",
|
|
68
|
-
"eslint-plugin-prettier": "^3.0.0",
|
|
69
|
-
"eslint-plugin-promise": "^4.0.1",
|
|
70
|
-
"eslint-plugin-react": "^7.10.0",
|
|
71
|
-
"eslint-plugin-standard": "^4.0.0",
|
|
72
|
-
"html-webpack-plugin": "^3.2.0",
|
|
73
|
-
"husky": "^1.2.1",
|
|
74
|
-
"jest": "^23.6.0",
|
|
41
|
+
"@babel/cli": "^7.8.4",
|
|
42
|
+
"@babel/core": "^7.8.4",
|
|
43
|
+
"@babel/node": "^7.8.4",
|
|
44
|
+
"@babel/preset-env": "^7.8.4",
|
|
45
|
+
"cross-env": "^7.0.0",
|
|
46
|
+
"eslint": "^6.8.0",
|
|
47
|
+
"eslint-config-prettier": "^6.10.0",
|
|
48
|
+
"eslint-config-standard": "^14.1.0",
|
|
49
|
+
"eslint-plugin-import": "^2.20.1",
|
|
50
|
+
"eslint-plugin-node": "^11.0.0",
|
|
51
|
+
"eslint-plugin-prettier": "^3.1.2",
|
|
52
|
+
"eslint-plugin-promise": "^4.2.1",
|
|
53
|
+
"eslint-plugin-standard": "^4.0.1",
|
|
54
|
+
"husky": "^4.2.1",
|
|
55
|
+
"jest": "^25.1.0",
|
|
75
56
|
"markdown-toc": "^1.2.0",
|
|
76
|
-
"
|
|
77
|
-
"mini-css-extract-plugin": "^0.4.5",
|
|
78
|
-
"mkdirp": "^0.5.1",
|
|
57
|
+
"mkdirp": "^1.0.3",
|
|
79
58
|
"npm-run-all": "^4.1.5",
|
|
80
59
|
"os-tmpdir": "^2.0.0",
|
|
81
60
|
"pkg-ok": "^2.3.1",
|
|
82
|
-
"
|
|
83
|
-
"
|
|
84
|
-
"promise-polyfill": "^8.1.0",
|
|
85
|
-
"rimraf": "^2.6.2",
|
|
61
|
+
"prettier": "^1.19.1",
|
|
62
|
+
"rimraf": "^3.0.2",
|
|
86
63
|
"server-ready": "^0.3.1",
|
|
87
|
-
"supertest": "^
|
|
88
|
-
"temp-write": "^
|
|
89
|
-
"webpack": "^4.28.2",
|
|
90
|
-
"webpack-cli": "^3.1.2",
|
|
91
|
-
"whatwg-fetch": "^3.0.0"
|
|
64
|
+
"supertest": "^4.0.2",
|
|
65
|
+
"temp-write": "^4.0.0"
|
|
92
66
|
},
|
|
93
67
|
"repository": {
|
|
94
68
|
"type": "git",
|
|
@@ -117,7 +91,7 @@
|
|
|
117
91
|
},
|
|
118
92
|
"homepage": "https://github.com/typicode/json-server",
|
|
119
93
|
"engines": {
|
|
120
|
-
"node": ">=
|
|
94
|
+
"node": ">=10"
|
|
121
95
|
},
|
|
122
96
|
"husky": {
|
|
123
97
|
"hooks": {
|
package/postinstall.js
ADDED
|
File without changes
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
<html>
|
|
2
|
+
<head>
|
|
3
|
+
<link
|
|
4
|
+
rel="stylesheet"
|
|
5
|
+
href="https://use.fontawesome.com/releases/v5.8.2/css/all.css"
|
|
6
|
+
integrity="sha384-oS3vJWv+0UjzBfQzYUhtDYW+Pj2yciDJxpsK1OYPAYjqT085Qq/1cq5FLXAZQ7Ay"
|
|
7
|
+
crossorigin="anonymous"
|
|
8
|
+
/>
|
|
9
|
+
<link rel="stylesheet" href="style.css" />
|
|
10
|
+
<title>JSON Server</title>
|
|
11
|
+
</head>
|
|
12
|
+
|
|
13
|
+
<body>
|
|
14
|
+
<header>
|
|
15
|
+
<div class="container">
|
|
16
|
+
<nav>
|
|
17
|
+
<ul>
|
|
18
|
+
<li class="title">
|
|
19
|
+
JSON Server
|
|
20
|
+
</li>
|
|
21
|
+
<li>
|
|
22
|
+
<a href="https://github.com/users/typicode/sponsorship">
|
|
23
|
+
<i class="fas fa-heart"></i>GitHub Sponsors
|
|
24
|
+
</a>
|
|
25
|
+
</li>
|
|
26
|
+
<li>
|
|
27
|
+
<a href="https://my-json-server.typicode.com">
|
|
28
|
+
<i class="fas fa-burn"></i>My JSON Server
|
|
29
|
+
</a>
|
|
30
|
+
</li>
|
|
31
|
+
<li>
|
|
32
|
+
<a href="https://thanks.typicode.com">
|
|
33
|
+
<i class="far fa-laugh"></i>Supporters
|
|
34
|
+
</a>
|
|
35
|
+
</li>
|
|
36
|
+
</ul>
|
|
37
|
+
</nav>
|
|
38
|
+
</div>
|
|
39
|
+
</header>
|
|
40
|
+
<main>
|
|
41
|
+
<div class="container">
|
|
42
|
+
<h1>Congrats!</h1>
|
|
43
|
+
<p>
|
|
44
|
+
You're successfully running JSON Server
|
|
45
|
+
<br />
|
|
46
|
+
✧*。٩(ˊᗜˋ*)و✧*。
|
|
47
|
+
</p>
|
|
48
|
+
|
|
49
|
+
<div id="resources"></div>
|
|
50
|
+
|
|
51
|
+
<p>
|
|
52
|
+
To access and modify resources, you can use any HTTP method:
|
|
53
|
+
</p>
|
|
54
|
+
<p>
|
|
55
|
+
<code>GET</code>
|
|
56
|
+
<code>POST</code>
|
|
57
|
+
<code>PUT</code>
|
|
58
|
+
<code>PATCH</code>
|
|
59
|
+
<code>DELETE</code>
|
|
60
|
+
<code>OPTIONS</code>
|
|
61
|
+
</p>
|
|
62
|
+
|
|
63
|
+
<div id="custom-routes"></div>
|
|
64
|
+
|
|
65
|
+
<h1>Documentation</h1>
|
|
66
|
+
<p>
|
|
67
|
+
<a href="https://github.com/typicode/json-server">
|
|
68
|
+
README
|
|
69
|
+
</a>
|
|
70
|
+
</p>
|
|
71
|
+
</div>
|
|
72
|
+
</main>
|
|
73
|
+
|
|
74
|
+
<footer>
|
|
75
|
+
<div class="container">
|
|
76
|
+
<p>
|
|
77
|
+
To replace this page, create a
|
|
78
|
+
<code>./public/index.html</code> file.
|
|
79
|
+
</p>
|
|
80
|
+
</div>
|
|
81
|
+
</footer>
|
|
82
|
+
|
|
83
|
+
<script src="script.js"></script>
|
|
84
|
+
</body>
|
|
85
|
+
</html>
|
package/public/script.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
function ResourceItem({ name, length }) {
|
|
2
|
+
return `
|
|
3
|
+
<li>
|
|
4
|
+
<a href="${name}">/${name}</a>
|
|
5
|
+
<sup>${length ? `${length}x` : 'object'}</sup>
|
|
6
|
+
</li>
|
|
7
|
+
`
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function ResourceList({ db }) {
|
|
11
|
+
return `
|
|
12
|
+
<ul>
|
|
13
|
+
${Object.keys(db)
|
|
14
|
+
.map(name =>
|
|
15
|
+
ResourceItem({
|
|
16
|
+
name,
|
|
17
|
+
length: Array.isArray(db[name]) && db[name].length
|
|
18
|
+
})
|
|
19
|
+
)
|
|
20
|
+
.join('')}
|
|
21
|
+
</ul>
|
|
22
|
+
`
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function NoResources() {
|
|
26
|
+
return `<p>No resources found</p>`
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function ResourcesBlock({ db }) {
|
|
30
|
+
return `
|
|
31
|
+
<div>
|
|
32
|
+
<h1>Resources</h1>
|
|
33
|
+
${Object.keys(db).length ? ResourceList({ db }) : NoResources()}
|
|
34
|
+
</div>
|
|
35
|
+
`
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
window
|
|
39
|
+
.fetch('db')
|
|
40
|
+
.then(response => response.json())
|
|
41
|
+
.then(
|
|
42
|
+
db =>
|
|
43
|
+
(document.getElementById('resources').innerHTML = ResourcesBlock({ db }))
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
function CustomRoutesBlock({ customRoutes }) {
|
|
47
|
+
const rules = Object.keys(customRoutes)
|
|
48
|
+
if (rules.length) {
|
|
49
|
+
return `
|
|
50
|
+
<div>
|
|
51
|
+
<h1>Custom Routes</h1>
|
|
52
|
+
<table>
|
|
53
|
+
${rules
|
|
54
|
+
.map(
|
|
55
|
+
rule =>
|
|
56
|
+
`<tr>
|
|
57
|
+
<td>${rule}</td>
|
|
58
|
+
<td><code>⇢</code> ${customRoutes[rule]}</td>
|
|
59
|
+
</tr>`
|
|
60
|
+
)
|
|
61
|
+
.join('')}
|
|
62
|
+
</table>
|
|
63
|
+
</div>
|
|
64
|
+
`
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
window
|
|
69
|
+
.fetch('__rules')
|
|
70
|
+
.then(response => response.json())
|
|
71
|
+
.then(
|
|
72
|
+
customRoutes =>
|
|
73
|
+
(document.getElementById('custom-routes').innerHTML = CustomRoutesBlock({
|
|
74
|
+
customRoutes
|
|
75
|
+
}))
|
|
76
|
+
)
|
package/public/style.css
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
body {
|
|
2
|
+
display: flex;
|
|
3
|
+
min-height: 100vh;
|
|
4
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
|
|
5
|
+
Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;
|
|
6
|
+
flex-direction: column;
|
|
7
|
+
padding: 0;
|
|
8
|
+
margin: 0;
|
|
9
|
+
color: #3b4252;
|
|
10
|
+
letter-spacing: 0;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.container {
|
|
14
|
+
max-width: 960px;
|
|
15
|
+
margin: auto;
|
|
16
|
+
padding: 1rem;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
header {
|
|
20
|
+
border-bottom: 1px solid #eee;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
header a {
|
|
24
|
+
color: inherit;
|
|
25
|
+
text-decoration: none;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
header a:hover {
|
|
29
|
+
text-decoration: underline;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
nav ul {
|
|
33
|
+
display: flex;
|
|
34
|
+
flex-wrap: nowrap;
|
|
35
|
+
justify-content: space-between;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
nav li.title {
|
|
39
|
+
flex-grow: 5;
|
|
40
|
+
text-align: left;
|
|
41
|
+
font-weight: bold;
|
|
42
|
+
font-size: 1.4rem;
|
|
43
|
+
color: #3b4252;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
nav li {
|
|
47
|
+
flex-grow: 1;
|
|
48
|
+
align-self: center;
|
|
49
|
+
text-align: right;
|
|
50
|
+
color: #4c566a;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.fa-heart {
|
|
54
|
+
color: deeppink;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
main {
|
|
58
|
+
flex: 1;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
footer {
|
|
62
|
+
margin-top: 4rem;
|
|
63
|
+
border-top: 1px solid #eee;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
h1 {
|
|
67
|
+
margin-top: 4rem;
|
|
68
|
+
font-weight: normal;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
i {
|
|
72
|
+
margin-right: 0.5rem;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
a {
|
|
76
|
+
color: #5e81ac;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
a:hover {
|
|
80
|
+
color: #81a1c1;
|
|
81
|
+
text-decoration: underline;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
table {
|
|
85
|
+
margin-left: 0;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
td {
|
|
89
|
+
border: 0;
|
|
90
|
+
padding: 0 1em 0.5em 0;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
td:first-child {
|
|
94
|
+
width: 1%;
|
|
95
|
+
white-space: nowrap;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
ul {
|
|
99
|
+
list-style-position: inside;
|
|
100
|
+
padding-left: 0;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
li {
|
|
104
|
+
list-style-type: none;
|
|
105
|
+
margin-bottom: 0.2rem;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
code {
|
|
109
|
+
padding: 0.2rem;
|
|
110
|
+
margin: 0rem 0.2rem;
|
|
111
|
+
border-radius: 0.2rem;
|
|
112
|
+
background: #e5e9f0;
|
|
113
|
+
}
|
package/dist/index.html
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
<html>
|
|
2
|
-
|
|
3
|
-
<head>
|
|
4
|
-
<title>JSON Server</title>
|
|
5
|
-
<link rel="shortcut icon" href="favicon.ico"><link href="main.css" rel="stylesheet"></head>
|
|
6
|
-
|
|
7
|
-
<body>
|
|
8
|
-
<header>
|
|
9
|
-
<div class="container">
|
|
10
|
-
<h3>JSON Server</h3>
|
|
11
|
-
</div>
|
|
12
|
-
</header>
|
|
13
|
-
<main>
|
|
14
|
-
<div class="container">
|
|
15
|
-
<h4>Congrats!</h4>
|
|
16
|
-
<p>
|
|
17
|
-
You're successfully running JSON Server
|
|
18
|
-
<br> ✧*。٩(ˊᗜˋ*)و✧*。
|
|
19
|
-
</p>
|
|
20
|
-
|
|
21
|
-
<div id="resources"></div>
|
|
22
|
-
|
|
23
|
-
<p>
|
|
24
|
-
To access and modify resources, you can use any HTTP method
|
|
25
|
-
<br>
|
|
26
|
-
<code>GET</code>
|
|
27
|
-
<code>POST</code>
|
|
28
|
-
<code>PUT</code>
|
|
29
|
-
<code>PATCH</code>
|
|
30
|
-
<code>DELETE</code>
|
|
31
|
-
<code>OPTIONS</code>
|
|
32
|
-
</p>
|
|
33
|
-
|
|
34
|
-
<div id="custom-routes"></div>
|
|
35
|
-
|
|
36
|
-
<h4>Documentation</h4>
|
|
37
|
-
<p>
|
|
38
|
-
View
|
|
39
|
-
<a href="https://github.com/typicode/json-server">README</a>
|
|
40
|
-
</p>
|
|
41
|
-
</div>
|
|
42
|
-
</main>
|
|
43
|
-
|
|
44
|
-
<footer>
|
|
45
|
-
<div class="container">
|
|
46
|
-
<p>
|
|
47
|
-
To replace this page, create a
|
|
48
|
-
<code>./public/index.html</code> file.
|
|
49
|
-
</p>
|
|
50
|
-
</div>
|
|
51
|
-
</footer>
|
|
52
|
-
<script type="text/javascript" src="main.js"></script></body>
|
|
53
|
-
</html>
|