json-server 0.16.0 → 0.17.0

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 CHANGED
@@ -1,4 +1,4 @@
1
- # JSON Server [![](https://travis-ci.org/typicode/json-server.svg?branch=master)](https://travis-ci.org/typicode/json-server) [![](https://badge.fury.io/js/json-server.svg)](http://badge.fury.io/js/json-server)
1
+ # JSON Server [![Node.js CI](https://github.com/typicode/json-server/actions/workflows/node.js.yml/badge.svg?branch=master)](https://github.com/typicode/json-server/actions/workflows/node.js.yml)
2
2
 
3
3
  Get a full fake REST API with __zero coding__ in __less than 30 seconds__ (seriously)
4
4
 
@@ -10,7 +10,8 @@ Created with <3 for front-end developers who need a quick back-end for prototypi
10
10
 
11
11
  See also:
12
12
  * :dog: [husky - Git hooks made easy](https://github.com/typicode/husky)
13
- * :hotel: [hotel - developer tool with local .localhost domain and https out of the box](https://github.com/typicode/hotel)
13
+ * :owl: [lowdb - local JSON database](https://github.com/typicode/lowdb)
14
+ * :x: :heavy_check_mark: [xv - the most minimalist test runner](https://github.com/typicode/xv)
14
15
 
15
16
  <p>&nbsp;</p>
16
17
 
@@ -26,20 +27,48 @@ See also:
26
27
 
27
28
  <p>&nbsp;</p>
28
29
 
29
- <h2 align="center">Bronze sponsors 🥉</h2>
30
+ <p align="center">
31
+ <a href="https://mockend.com/" target="_blank">
32
+ <img src="https://jsonplaceholder.typicode.com/mockend.svg" height="70px">
33
+ </a>
34
+ </p>
35
+
36
+ <p>&nbsp;</p>
37
+
38
+ <p align="center">
39
+ <a href="https://www.deta.sh/?ref=typicode" target="_blank">
40
+ <img src="https://jsonplaceholder.typicode.com/deta.svg" height="70px">
41
+ </a>
42
+ </p>
30
43
 
31
44
  <p>&nbsp;</p>
32
45
 
33
46
  <p align="center">
34
- <a href="https://www.zinggrid.com/hello/json-server?utm_source=jsonserver&utm_medium=github&utm_campaign=sponsorship" target="_blank">
35
- <img src="https://i.imgur.com/3mJGTAQ.png" height="30px">
47
+ <a href="https://uibakery.io/?utm_source=json_server&utm_medium=sponsor&utm_campaign=github" target="_blank">
48
+ <img src="https://jsonplaceholder.typicode.com/ui_bakery.jpg" height="70px">
36
49
  </a>
37
50
  </p>
38
51
 
39
52
  <p>&nbsp;</p>
40
53
 
54
+ <p>&nbsp;</p>
55
+
56
+ ---
57
+
58
+ From generating an API to importing a CSV into postgres, Retool’s range of 20+ developer utilities is a go-to resource when building apps. [Check it out now](https://retool.com/utilities/)
59
+
60
+ ---
61
+
62
+ <p>&nbsp;</p>
63
+
64
+ <p>&nbsp;</p>
65
+
41
66
  [Become a sponsor and have your company logo here](https://github.com/users/typicode/sponsorship)
42
67
 
68
+ ## Sponsor
69
+
70
+ __Please help me build OSS__ 👉 [GitHub Sponsors](https://github.com/sponsors/typicode) :heart:
71
+
43
72
  ## Table of contents
44
73
 
45
74
  <!-- toc -->
@@ -123,7 +152,7 @@ Also when doing requests, it's good to know that:
123
152
  - 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).
124
153
  - Your request body JSON should be object enclosed, just like the GET output. (for example `{"name": "Foobar"}`)
125
154
  - 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.
126
- - 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.
155
+ - 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 return a 2XX status code, but without changes being made to the data.
127
156
 
128
157
  ## Routes
129
158
 
@@ -591,7 +620,6 @@ You can deploy JSON Server. For example, [JSONPlaceholder](http://jsonplaceholde
591
620
  ### Articles
592
621
 
593
622
  * [Node Module Of The Week - json-server](http://nmotw.in/json-server/)
594
- * [Mock up your REST API with JSON Server](http://www.betterpixels.co.uk/projects/2015/05/09/mock-up-your-rest-api-with-json-server/)
595
623
  * [ng-admin: Add an AngularJS admin GUI to any RESTful API](http://marmelab.com/blog/2014/09/15/easy-backend-for-your-restful-api.html)
596
624
  * [Fast prototyping using Restangular and Json-server](https://glebbahmutov.com/blog/fast-prototyping-restangular-and-json-server/)
597
625
  * [Create a Mock REST API in Seconds for Prototyping your Frontend](https://coligo.io/create-mock-rest-api-with-json-server/)
package/lib/cli/run.js CHANGED
@@ -33,7 +33,7 @@ function prettyPrint(argv, object, rules) {
33
33
  console.log();
34
34
  console.log(chalk.bold(' Other routes'));
35
35
 
36
- for (var rule in rules) {
36
+ for (const rule in rules) {
37
37
  console.log(` ${rule} -> ${rules[rule]}`);
38
38
  }
39
39
  }
@@ -4,7 +4,9 @@ const fs = require('fs');
4
4
 
5
5
  const path = require('path');
6
6
 
7
- const request = require('request');
7
+ const http = require('http');
8
+
9
+ const https = require('https');
8
10
 
9
11
  const low = require('lowdb');
10
12
 
@@ -44,14 +46,20 @@ module.exports = function (source) {
44
46
 
45
47
  resolve(low(new FileAsync(source)));
46
48
  } else if (is.URL(source)) {
47
- // Load remote data
48
- const opts = {
49
- url: source,
50
- json: true
51
- };
52
- request(opts, (err, response) => {
53
- if (err) return reject(err);
54
- resolve(low(new Memory()).setState(response.body));
49
+ // Normalize the source into a URL object.
50
+ const sourceUrl = new URL(source); // Pick the client based on the protocol scheme
51
+
52
+ const client = sourceUrl.protocol === 'https:' ? https : http;
53
+ client.get(sourceUrl, res => {
54
+ let dbData = '';
55
+ res.on('data', data => {
56
+ dbData += data;
57
+ });
58
+ res.on('end', () => {
59
+ resolve(low(new Memory()).setState(JSON.parse(dbData)));
60
+ });
61
+ }).on('error', error => {
62
+ return reject(error);
55
63
  });
56
64
  } else if (is.JS(source)) {
57
65
  // Clear cache
@@ -18,7 +18,7 @@ const bodyParser = require('./body-parser');
18
18
 
19
19
  module.exports = function (opts) {
20
20
  const userDir = path.join(process.cwd(), 'public');
21
- const defaultDir = path.join(__dirname, '../front');
21
+ const defaultDir = path.join(__dirname, '../../public');
22
22
  const staticDir = fs.existsSync(userDir) ? userDir : defaultDir;
23
23
  opts = Object.assign({
24
24
  logger: true,
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
 
3
- const nanoid = require('nanoid');
3
+ const {
4
+ nanoid
5
+ } = require('nanoid');
4
6
 
5
7
  const pluralize = require('pluralize');
6
8
 
@@ -75,7 +75,7 @@ module.exports = (db, opts) => {
75
75
  return;
76
76
  }
77
77
 
78
- var sourceMessage = ''; // if (!_.isObject(source)) {
78
+ const sourceMessage = ''; // if (!_.isObject(source)) {
79
79
  // sourceMessage = `in ${source}`
80
80
  // }
81
81
 
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
3
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
4
4
 
5
5
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
6
6
 
@@ -103,6 +103,8 @@ module.exports = (db, name, opts) => {
103
103
  return true;
104
104
  }
105
105
  }
106
+
107
+ return false;
106
108
  });
107
109
  }
108
110
 
@@ -124,7 +126,7 @@ module.exports = (db, name, opts) => {
124
126
 
125
127
 
126
128
  if (elementValue === undefined || elementValue === null) {
127
- return;
129
+ return undefined;
128
130
  }
129
131
 
130
132
  if (isRange) {
@@ -230,7 +232,7 @@ module.exports = (db, name, opts) => {
230
232
 
231
233
  if (opts._isFake) {
232
234
  const id = db.get(name).createId().value();
233
- resource = _objectSpread({}, req.body, {
235
+ resource = _objectSpread(_objectSpread({}, req.body), {}, {
234
236
  id
235
237
  });
236
238
  } else {
@@ -254,9 +256,9 @@ module.exports = (db, name, opts) => {
254
256
  resource = db.get(name).getById(id).value();
255
257
 
256
258
  if (req.method === 'PATCH') {
257
- resource = _objectSpread({}, resource, {}, req.body);
259
+ resource = _objectSpread(_objectSpread({}, resource), req.body);
258
260
  } else {
259
- resource = _objectSpread({}, req.body, {
261
+ resource = _objectSpread(_objectSpread({}, req.body), {}, {
260
262
  id: resource.id
261
263
  });
262
264
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
3
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
4
4
 
5
5
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
6
6
 
@@ -43,7 +43,7 @@ module.exports = (db, name, opts) => {
43
43
  res.locals.data = req.body;
44
44
  } else {
45
45
  const resource = db.get(name).value();
46
- res.locals.data = _objectSpread({}, resource, {}, req.body);
46
+ res.locals.data = _objectSpread(_objectSpread({}, resource), req.body);
47
47
  }
48
48
  } else {
49
49
  if (req.method === 'PUT') {
@@ -5,9 +5,9 @@ module.exports = {
5
5
  };
6
6
 
7
7
  function getPage(array, page, perPage) {
8
- var obj = {};
9
- var start = (page - 1) * perPage;
10
- var end = page * perPage;
8
+ const obj = {};
9
+ const start = (page - 1) * perPage;
10
+ const end = page * perPage;
11
11
  obj.items = array.slice(start, end);
12
12
 
13
13
  if (obj.items.length === 0) {
package/package.json CHANGED
@@ -1,10 +1,15 @@
1
1
  {
2
2
  "name": "json-server",
3
- "version": "0.16.0",
3
+ "version": "0.17.0",
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",
7
+ "files": [
8
+ "lib",
9
+ "public"
10
+ ],
7
11
  "scripts": {
12
+ "prepare": "husky install",
8
13
  "test": "npm run build && cross-env NODE_ENV=test jest && npm run lint",
9
14
  "start": "babel-node -- src/cli/bin db.json -r routes.json",
10
15
  "lint": "eslint . --ignore-path .gitignore",
@@ -12,56 +17,54 @@
12
17
  "build": "babel src -d lib",
13
18
  "toc": "markdown-toc -i README.md",
14
19
  "postversion": "git push && git push --tags",
15
- "prepublishOnly": "npm test && npm run build && pkg-ok"
20
+ "prepublish": "npm test && npm run build"
16
21
  },
17
22
  "dependencies": {
18
23
  "body-parser": "^1.19.0",
19
- "chalk": "^3.0.0",
24
+ "chalk": "^4.1.2",
20
25
  "compression": "^1.7.4",
21
26
  "connect-pause": "^0.1.1",
22
27
  "cors": "^2.8.5",
23
28
  "errorhandler": "^1.5.1",
24
29
  "express": "^4.17.1",
25
- "express-urlrewrite": "^1.2.0",
30
+ "express-urlrewrite": "^1.4.0",
26
31
  "json-parse-helpfulerror": "^1.0.3",
27
- "lodash": "^4.17.15",
28
- "lodash-id": "^0.14.0",
32
+ "lodash": "^4.17.21",
33
+ "lodash-id": "^0.14.1",
29
34
  "lowdb": "^1.0.0",
30
35
  "method-override": "^3.0.0",
31
- "morgan": "^1.9.1",
32
- "nanoid": "^2.1.11",
36
+ "morgan": "^1.10.0",
37
+ "nanoid": "^3.1.23",
33
38
  "please-upgrade-node": "^3.2.0",
34
39
  "pluralize": "^8.0.0",
35
- "request": "^2.88.2",
36
40
  "server-destroy": "^1.0.1",
37
- "update-notifier": "^4.0.0",
38
- "yargs": "^15.1.0"
41
+ "update-notifier": "^5.1.0",
42
+ "yargs": "^17.0.1"
39
43
  },
40
44
  "devDependencies": {
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",
45
+ "@babel/cli": "^7.12.1",
46
+ "@babel/core": "^7.12.3",
47
+ "@babel/node": "^7.12.6",
48
+ "@babel/preset-env": "^7.12.1",
49
+ "cross-env": "^7.0.2",
50
+ "eslint": "^7.13.0",
51
+ "eslint-config-prettier": "^8.3.0",
52
+ "eslint-config-standard": "^16.0.1",
53
+ "eslint-plugin-import": "^2.22.1",
54
+ "eslint-plugin-node": "^11.1.0",
55
+ "eslint-plugin-prettier": "^3.1.4",
52
56
  "eslint-plugin-promise": "^4.2.1",
53
- "eslint-plugin-standard": "^4.0.1",
54
- "husky": "^4.2.1",
55
- "jest": "^25.1.0",
57
+ "eslint-plugin-standard": "^4.1.0",
58
+ "husky": "^6.0.0",
59
+ "jest": "^26.6.3",
56
60
  "markdown-toc": "^1.2.0",
57
- "mkdirp": "^1.0.3",
61
+ "mkdirp": "^1.0.4",
58
62
  "npm-run-all": "^4.1.5",
59
63
  "os-tmpdir": "^2.0.0",
60
- "pkg-ok": "^2.3.1",
61
- "prettier": "^1.19.1",
64
+ "prettier": "^2.3.2",
62
65
  "rimraf": "^3.0.2",
63
66
  "server-ready": "^0.3.1",
64
- "supertest": "^4.0.2",
67
+ "supertest": "^6.0.1",
65
68
  "temp-write": "^4.0.0"
66
69
  },
67
70
  "repository": {
@@ -91,12 +94,7 @@
91
94
  },
92
95
  "homepage": "https://github.com/typicode/json-server",
93
96
  "engines": {
94
- "node": ">=10"
95
- },
96
- "husky": {
97
- "hooks": {
98
- "pre-commit": "npm test"
99
- }
97
+ "node": ">=12"
100
98
  },
101
99
  "jest": {
102
100
  "testURL": "http://localhost/"
Binary file
@@ -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>
@@ -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
+ )
@@ -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/.babelrc DELETED
@@ -1,12 +0,0 @@
1
- {
2
- "presets": [
3
- [
4
- "@babel/preset-env",
5
- {
6
- "targets": {
7
- "node": "8"
8
- }
9
- }
10
- ]
11
- ]
12
- }
package/.eslintignore DELETED
@@ -1,2 +0,0 @@
1
- src/server/public
2
- lib
package/.eslintrc.js DELETED
@@ -1,14 +0,0 @@
1
- module.exports = {
2
- extends: ['standard', 'prettier'],
3
- plugins: ['prettier'],
4
- rules: {
5
- 'prettier/prettier': [
6
- 'error',
7
- {
8
- singleQuote: true,
9
- semi: false,
10
- },
11
- ]
12
- },
13
- env: { jest: true }
14
- }
@@ -1,2 +0,0 @@
1
- github: typicode
2
- patreon: typicode
@@ -1,31 +0,0 @@
1
- name: CI
2
-
3
- on: [push, pull_request]
4
-
5
- jobs:
6
- test:
7
- strategy:
8
- matrix:
9
- platform: [ubuntu-latest]
10
- node: [ '10', '12' ]
11
- name: Node ${{ matrix.node }} (${{ matrix.platform }})
12
- runs-on: ${{ matrix.platform }}
13
- steps:
14
- - uses: actions/checkout@v1
15
- - uses: actions/setup-node@v1
16
- with:
17
- node-version: ${{ matrix.node }}
18
- - name: install dependencies
19
- run: npm i
20
- - name: run tests
21
- run: npm test
22
- test_latest:
23
- runs-on: ubuntu-latest
24
- container: node:latest
25
- name: Node latest (ubuntu-latest)
26
- steps:
27
- - uses: actions/checkout@v1
28
- - name: install dependencies
29
- run: npm i
30
- - name: run tests
31
- run: npm test
package/.travis.yml DELETED
@@ -1,6 +0,0 @@
1
- language: node_js
2
- node_js:
3
- - "node"
4
- - "12"
5
- - "10"
6
- install: npm i
package/CHANGELOG.md DELETED
@@ -1,303 +0,0 @@
1
- # Change Log
2
-
3
- Changes for 0.15.1+ can now be found in https://github.com/typicode/json-server/releases
4
-
5
- ## 0.15.0 - 2019-05-21
6
-
7
- * __Breaking__ Require Node 8
8
- * Upgrade dependencies
9
- * Reduce package size
10
-
11
- ## 0.14.2 - 2018-12-26
12
-
13
- * Fix `db.getState is not a function`
14
-
15
- ## 0.14.1 - 2018-12-25
16
-
17
- * Show error message if port is already used
18
- * Upgrade to [lowdb](https://github.com/typicode/lowdb) `1.0`
19
-
20
- ## 0.14.0 - 2018-06-09
21
-
22
- * Listen to `localhost` by default, instead of `0.0.0.0`
23
-
24
- ## 0.13.0 - 2018-05-30
25
-
26
- * Bundle all index page assets so that you access it without network connection
27
- * Drop Node 4 support
28
-
29
- ## 0.12.2 - 2018-04-26
30
-
31
- * Add `_delay` query parameter
32
- * Upgrade `please-upgrade-node` dependency
33
-
34
- ## 0.12.1 - 2017-11-02
35
-
36
- * Disable logging for static content requests
37
- * Remove bad `console.log`
38
- * Update `dependencies`
39
- * Use [`nanoid`](https://github.com/ai/nanoid)
40
-
41
- ## 0.12.0 - 2017-08-02
42
-
43
- Re-include `body-parser` in `jsonServer.defaults()`
44
-
45
- If you're using JSON Server in an Express server and experience issues, you can disable it by passing
46
-
47
- ```js
48
- jsonServer.defaults({ bodyParser: false })
49
- ```
50
-
51
- ## 0.11.2 - 2017-07-10
52
-
53
- Fix `engines` field in `package.json`
54
-
55
- ## 0.11.1 - 2017-07-10
56
-
57
- Add [please-upgrade-node](https://github.com/typicode/please-upgrade-node)
58
-
59
- ## 0.11.0 - 2017-07-05
60
-
61
- Switch to [express-urlrewrite](https://github.com/kapouer/express-urlrewrite) to support rewriting query parameters (e.g. `/articles?id=1 # → /posts/1`)
62
-
63
- If you're rewriting default routes, you'll need to update your `routes.json` file
64
- (see [add custom routes](https://github.com/typicode/json-server#add-custom-routes) for updated doc).
65
-
66
- ## 0.10.3 - 2017-06-28
67
-
68
- * Fix `line-break` error in CLI
69
-
70
- ## 0.10.2 - 2017-06-28
71
-
72
- * Add `--foreignKeySuffix` option (e.g. snake case `post_id`) [#556](https://github.com/typicode/json-server/pull/556) [#570](https://github.com/typicode/json-server/pull/570)
73
-
74
- ## 0.10.1 - 2017-05-16
75
-
76
- * Multiple fields sorting `GET /posts?_sort=user,views&_order=desc,asc`
77
-
78
- ## 0.10.0 - 2017-04-26
79
-
80
- * __Drop Node `v0.12` support__
81
- * Prevent `TypeError` when a filter is applied on a `null` value [#510](https://github.com/typicode/json-server/issues/510)
82
-
83
- ## 0.9.6 - 2017-03-08
84
-
85
- * Update index page
86
- * Improve performances ([lowdb](https://github.com/typicode/lowdb) `v0.15`)
87
- * Add `Location` header to newly created resources [#473](https://github.com/typicode/json-server/pull/473)
88
-
89
- ## 0.9.5 - 2017-02-11
90
-
91
- * Display custom routes on homepage
92
- * Fix duplicate query params error [#352](https://github.com/typicode/json-server/issues/352)
93
-
94
- ## 0.9.4 - 2016-12-08
95
-
96
- * Improve rewriter [#431](https://github.com/typicode/json-server/issues/431)
97
- * Improve watch mode [#427](https://github.com/typicode/json-server/pull/427)
98
-
99
- ## 0.9.3 - 2016-12-07
100
-
101
- * Fix [#396](https://github.com/typicode/json-server/issues/396) PUT/PATCH saves the updated item with an id that has been converted to string
102
-
103
- ## 0.9.2 - 2016-11-29
104
-
105
- * Fix [#221](https://github.com/typicode/json-server/issues/221) `nohup` support
106
- * Fix [#420](https://github.com/typicode/json-server/issues/420) TypeError when watching `db.json`
107
-
108
- ## 0.9.1 - 2016-11-21
109
-
110
- * Fix
111
- * [#412](https://github.com/typicode/json-server/issues/412)
112
- * [#451](https://github.com/typicode/json-server/issues/411)
113
-
114
- ## 0.9.0 - 2016-11-11
115
-
116
- * Shorter `uuid`
117
- * No automatic conversion of strings to boolean or integer
118
- * Create a default `db.json` file if it doesn't exist
119
- * Fix
120
- * [#361](https://github.com/typicode/json-server/issues/361)
121
- * [#363](https://github.com/typicode/json-server/issues/363) [#365](https://github.com/typicode/json-server/issues/365)
122
- * [#374](https://github.com/typicode/json-server/issues/374)
123
- * [#383](https://github.com/typicode/json-server/issues/383)
124
- * Updated dependencies and codebase to ES6
125
-
126
- ## 0.8.23 - 2016-11-03
127
-
128
- * Fix `Links` header
129
-
130
- ## 0.8.22 - 2016-10-04
131
-
132
- * Fix `Links` header issue when using `_page`
133
- * Add query params support to the route rewriter
134
-
135
- ## 0.8.21 - 2016-09-13
136
-
137
- * Fix bodyParser issue when using custom routes
138
-
139
- ## 0.8.20 - 2016-09-12
140
-
141
- * Fix [#355](https://github.com/typicode/json-server/issues/355)
142
- * Add `_page` support
143
-
144
- ## 0.8.19 - 2016-08-18
145
-
146
- * Fix [#341](https://github.com/typicode/json-server/issues/341)
147
-
148
- ## 0.8.18 - 2016-08-17
149
-
150
- * Add CLI option `--middlewares` and support them in `json-server.json` config file
151
-
152
- ## 0.8.17 - 2016-07-25
153
-
154
- * Fix snapshot creation for JS files (ex: `json-server generator.js`)
155
-
156
- ## 0.8.16 - 2016-07-11
157
-
158
- * Support `x-www-form-urlencoded`
159
-
160
- ## 0.8.15 - 2016-07-03
161
-
162
- * Bug fix: `--watch` option on OS X
163
-
164
- ## 0.8.14 - 2016-05-15
165
-
166
- * Bug fix: data wasn't written to file in `v0.8.13` and `v0.8.12`
167
-
168
- ## 0.8.13 - 2016-05-12
169
-
170
- * Make `_like` operator case insensitive
171
-
172
- ## 0.8.12 - 2016-05-08
173
-
174
- * Minor bug fix
175
-
176
- ## 0.8.11 - 2016-05-08
177
-
178
- * Support sort by nested field (e.g. `_sort=author.name`)
179
- * Fix `graceful-fs` warning
180
-
181
- ## 0.8.10 - 2016-04-18
182
-
183
- * CLI option `-ng/--no-gzip` to disable `gzip` compression
184
-
185
- ## 0.8.9 - 2016-03-17
186
-
187
- * CLI can now read options from `json-server.json` if present
188
- * CLI option `-c/--config` to point to a different configuration file
189
-
190
- ## 0.8.8 - 2016-02-13
191
-
192
- ### Fixed
193
-
194
- * Fix #233
195
-
196
- ## 0.8.7 - 2016-01-22
197
-
198
- ### Added
199
-
200
- * `gzip` compression to improve performances
201
- * CLI option `-nc/--no-cors` to disable CORS
202
-
203
- ## 0.8.6 - 2016-01-07
204
-
205
- ### Added
206
-
207
- * CLI option `-ro/--read-only` to allow only GET requests
208
-
209
- ## 0.8.5 - 2015-12-28
210
-
211
- ### Fixed
212
-
213
- * Fix #177
214
-
215
- ## 0.8.4 - 2015-12-13
216
-
217
- ### Added
218
-
219
- * Like operator `GET /posts?title_like=json` (accepts RegExp)
220
-
221
- ## 0.8.3 - 2015-11-25
222
-
223
- ### Added
224
-
225
- * CLI option `-q/--quiet`
226
- * Nested route `POST /posts/1/comments`
227
- * Not equal operator `GET /posts?id_ne=1`
228
-
229
- ## 0.8.2 - 2015-10-15
230
-
231
- ### Added
232
-
233
- * CLI option `-S/--snapshots` to set a custom snapshots directory.
234
-
235
- ### Fixed
236
-
237
- * Fix plural resources: `DELETE` should return `404` if resource doesn't exist.
238
-
239
- ## 0.8.1 - 2015-10-06
240
-
241
- ### Fixed
242
-
243
- * Fix plural resources: `PUT` should replace resource instead of updating properties.
244
- * Fix singular resources: `POST`, `PUT`, `PATCH` should not convert resource properties.
245
-
246
- ## 0.8.0 - 2015-09-21
247
-
248
- ### Changed
249
-
250
- * `jsonServer.defaults` is now a function and can take an object.
251
- If you're using the project as a module, you need to update your code:
252
-
253
- ```js
254
- // Before
255
- jsonServer.defaults
256
- // After
257
- jsonServer.defaults()
258
- jsonServer.defaults({ static: '/some/path'})
259
- ```
260
-
261
- * Automatically ignore unknown query parameters.
262
-
263
- ```bash
264
- # Before
265
- GET /posts?author=typicode&foo=bar # []
266
- # After
267
- GET /posts?author=typicode&foo=bar # [{...}, {...}]
268
- ```
269
-
270
- ### Added
271
-
272
- * CLI option for setting a custom static files directory.
273
-
274
- ```bash
275
- json-server --static some/path
276
- ```
277
-
278
- ## 0.7.28 - 2015-09-09
279
-
280
- ```bash
281
- # Support range
282
- GET /products?price_gte=50&price_lte=100
283
- ```
284
-
285
- ## 0.7.27 - 2015-09-02
286
-
287
- ### Added
288
-
289
- ```bash
290
- # Support OR
291
- GET /posts?id=1&id2
292
- GET /posts?category=javascript&category=html
293
- ```
294
-
295
- ## 0.7.26 - 2015-09-01
296
-
297
- ### Added
298
-
299
- ```bash
300
- # Support embed and expand in lists
301
- GET /posts?embed=comments
302
- GET /posts?expand=user
303
- ```
package/appveyor.yml DELETED
@@ -1,21 +0,0 @@
1
- # Test against this version of Node.js
2
- environment:
3
- nodejs_version: "8"
4
-
5
- # Install scripts. (runs after repo cloning)
6
- install:
7
- # Get the latest stable version of Node.js
8
- - ps: Install-Product node $env:nodejs_version
9
- # install modules
10
- - npm install
11
-
12
- # Post-install test scripts.
13
- test_script:
14
- # Output useful info for debugging.
15
- - node --version
16
- - npm --version
17
- # run tests
18
- - npm test
19
-
20
- # Don't actually build.
21
- build: off
package/db.json DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "posts": [
3
- { "id": 1, "title": "json-server", "author": "typicode" }
4
- ],
5
- "comments": [
6
- { "id": 1, "body": "some comment", "postId": 1 }
7
- ],
8
- "profile": { "name": "typicode" }
9
- }
@@ -1,71 +0,0 @@
1
- "use strict";
2
-
3
- function ResourceItem({
4
- name,
5
- length
6
- }) {
7
- return `
8
- <li>
9
- <a href="${name}">/${name}</a>
10
- <sup>${length ? `${length}x` : 'object'}</sup>
11
- </li>
12
- `;
13
- }
14
-
15
- function ResourceList({
16
- db
17
- }) {
18
- return `
19
- <ul>
20
- ${Object.keys(db).map(name => ResourceItem({
21
- name,
22
- length: Array.isArray(db[name]) && db[name].length
23
- })).join('')}
24
- </ul>
25
- `;
26
- }
27
-
28
- function NoResources() {
29
- return `<p>No resources found</p>`;
30
- }
31
-
32
- function ResourcesBlock({
33
- db
34
- }) {
35
- return `
36
- <div>
37
- <h1>Resources</h1>
38
- ${Object.keys(db).length ? ResourceList({
39
- db
40
- }) : NoResources()}
41
- </div>
42
- `;
43
- }
44
-
45
- window.fetch('db').then(response => response.json()).then(db => document.getElementById('resources').innerHTML = ResourcesBlock({
46
- db
47
- }));
48
-
49
- function CustomRoutesBlock({
50
- customRoutes
51
- }) {
52
- const rules = Object.keys(customRoutes);
53
-
54
- if (rules.length) {
55
- return `
56
- <div>
57
- <h1>Custom Routes</h1>
58
- <table>
59
- ${rules.map(rule => `<tr>
60
- <td>${rule}</td>
61
- <td><code>⇢</code> ${customRoutes[rule]}</td>
62
- </tr>`).join('')}
63
- </table>
64
- </div>
65
- `;
66
- }
67
- }
68
-
69
- window.fetch('__rules').then(response => response.json()).then(customRoutes => document.getElementById('custom-routes').innerHTML = CustomRoutesBlock({
70
- customRoutes
71
- }));
@@ -1,71 +0,0 @@
1
- "use strict";
2
-
3
- function ResourceItem({
4
- name,
5
- length
6
- }) {
7
- return `
8
- <li>
9
- <a href="${name}">/${name}</a>
10
- <sup>${length ? `${length}x` : 'object'}</sup>
11
- </li>
12
- `;
13
- }
14
-
15
- function ResourceList({
16
- db
17
- }) {
18
- return `
19
- <ul>
20
- ${Object.keys(db).map(name => ResourceItem({
21
- name,
22
- length: Array.isArray(db[name]) && db[name].length
23
- })).join('')}
24
- </ul>
25
- `;
26
- }
27
-
28
- function NoResources() {
29
- return `<p>No resources found</p>`;
30
- }
31
-
32
- function ResourcesBlock({
33
- db
34
- }) {
35
- return `
36
- <div>
37
- <h1>Resources</h1>
38
- ${Object.keys(db).length ? ResourceList({
39
- db
40
- }) : NoResources()}
41
- </div>
42
- `;
43
- }
44
-
45
- window.fetch('db').then(response => response.json()).then(db => document.getElementById('resources').innerHTML = ResourcesBlock({
46
- db
47
- }));
48
-
49
- function CustomRoutesBlock({
50
- customRoutes
51
- }) {
52
- const rules = Object.keys(customRoutes);
53
-
54
- if (rules.length) {
55
- return `
56
- <div>
57
- <h1>Custom Routes</h1>
58
- <table>
59
- ${rules.map(rule => `<tr>
60
- <td>${rule}</td>
61
- <td><code>⇢</code> ${customRoutes[rule]}</td>
62
- </tr>`).join('')}
63
- </table>
64
- </div>
65
- `;
66
- }
67
- }
68
-
69
- window.fetch('__rules').then(response => response.json()).then(customRoutes => document.getElementById('custom-routes').innerHTML = CustomRoutesBlock({
70
- customRoutes
71
- }));
package/postinstall.js DELETED
@@ -1,10 +0,0 @@
1
- const chalk = require('chalk')
2
-
3
- console.log(
4
- 'Like JSON Server? You can support the project on',
5
- chalk.bold('GitHub Sponsors')
6
- )
7
- console.log(
8
- chalk.underline('https://github.com/users/typicode/sponsorship'),
9
- chalk.red('❤')
10
- )
package/routes.json DELETED
@@ -1,5 +0,0 @@
1
- {
2
- "/api/": "/",
3
- "/blog/:resource/:id/show": "/:resource/:id",
4
- "/blog/:category": "/posts?category=:category"
5
- }