Skip to content

Commit 2b26630

Browse files
authored
v0.9.0 (typicode#404)
* Remove automatic type conversion * Remove body-parser from default middlewares * Ignore lib * ES2015 * Use shortid * Add babel-register * Update paths to ./lib * Add .npmignore * Update bin * temp fix * Fix bin * Add message when creating default db * Use fs.watch * Fix operator existence test * Fix 0.12 tests * Update dependencies * Update * Increase timeout * Fix 0.12 support * 0.9.0-beta.1 * Fix missing example.json issue * 0.9.0-beta.2 * Update message * Update CHANGELOG.md * Update lowdb dependency * Add error message * Update README.md * Add database validation * Update * Update * Fix tests * Update
1 parent 44bdfb4 commit 2b26630

32 files changed

+828
-689
lines changed

.babelrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"presets": [
3-
"es2015"
3+
["es2015", { "loose": true }]
44
]
55
}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
**/*.log
22
node_modules
33
tmp
4+
lib
45
.DS_Store
56
.idea

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
src

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# Change Log
22

3+
## [0.9.0][2016-11-11]
4+
5+
* Shorter `uuid`
6+
* No automatic conversion of strings to boolean or integer
7+
* Create a default `db.json` file if it doesn't exist
8+
* Fix
9+
* [#361](https://github.com/typicode/json-server/issues/361)
10+
* [#363](https://github.com/typicode/json-server/issues/363) [#365](https://github.com/typicode/json-server/issues/365)
11+
* [#374](https://github.com/typicode/json-server/issues/374)
12+
* [#383](https://github.com/typicode/json-server/issues/383)
13+
* Updated dependencies and codebase to ES6
14+
315
## [0.8.23][2016-11-03]
416

517
* Fix `Links` header

README.md

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,14 @@ GET /comments?author.name=typicode
9797

9898
### Paginate
9999

100-
Add `_page` and in the `Link` header you'll get `first`, `prev`, `next` and `last` links
100+
Use `_page` and optionally `_limit` to paginate returned data.
101+
102+
In the `Link` header you'll get `first`, `prev`, `next` and `last` links.
103+
101104

102105
```
103106
GET /posts?_page=7
107+
GET /posts?_page=7&_limit=20
104108
```
105109

106110
_10 items are returned by default_
@@ -247,16 +251,21 @@ module.exports = function() {
247251
$ json-server index.js
248252
```
249253

250-
__Tip__ use modules like [faker](https://github.com/Marak/faker.js), [casual](https://github.com/boo1ean/casual) or [chance](https://github.com/victorquinn/chancejs).
254+
__Tip__ use modules like [Faker](https://github.com/Marak/faker.js), [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).
255+
256+
### HTTPS
251257

252-
### Add routes
258+
There's many way to set up SSL in development. One simple way though is to use [hotel](https://github.com/typicode/hotel).
253259

254-
Create a `routes.json` file. Pay attention to start every route with /.
260+
### Add custom routes
261+
262+
Create a `routes.json` file. Pay attention to start every route with `/`.
255263

256264
```json
257265
{
258266
"/api/": "/",
259-
"/blog/:resource/:id/show": "/:resource/:id"
267+
"/blog/:resource/:id/show": "/:resource/:id",
268+
"/blog/:category": "/posts/:id?category=:category"
260269
}
261270
```
262271

@@ -268,10 +277,11 @@ json-server db.json --routes routes.json
268277

269278
Now you can access resources using additional routes.
270279

271-
```bash
272-
/api/posts
273-
/api/posts/1
274-
/blog/posts/1/show
280+
```sh
281+
/api/posts # → /posts
282+
/api/posts/1 # → /posts/1
283+
/blog/posts/1/show # → /posts/1
284+
/blog/javascript # → /posts?category=javascript
275285
```
276286

277287
### Add middlewares
@@ -383,6 +393,9 @@ server.get('/echo', function (req, res) {
383393
res.jsonp(req.query)
384394
})
385395

396+
// To handle POST, PUT and PATCH you need to use a body-parser
397+
// You can use the one used by JSON Server
398+
server.use(jsonServer.bodyParser)
386399
server.use(function (req, res, next) {
387400
if (req.method === 'POST') {
388401
req.body.createdAt = Date.now()

bin/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#!/usr/bin/env node
2-
require('../src/cli')()
2+
require('../lib/cli/bin')

package.json

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,55 @@
11
{
22
"name": "json-server",
3-
"version": "0.8.23",
3+
"version": "0.9.0-beta.2",
44
"description": "Serves JSON files through REST routes.",
5-
"main": "./src/server/index.js",
5+
"main": "./lib/server/index.js",
66
"bin": "./bin/index.js",
77
"directories": {
88
"test": "test"
99
},
1010
"dependencies": {
1111
"body-parser": "^1.15.2",
1212
"chalk": "^1.1.3",
13-
"chokidar": "^1.6.0",
1413
"compression": "^1.6.0",
1514
"connect-pause": "^0.1.0",
1615
"cors": "^2.3.0",
1716
"errorhandler": "^1.2.0",
1817
"express": "^4.9.5",
1918
"lodash": "^4.11.2",
20-
"lowdb": "^0.13.1",
19+
"lowdb": "^0.14.0",
2120
"method-override": "^2.1.2",
2221
"morgan": "^1.3.1",
23-
"node-uuid": "^1.4.2",
2422
"object-assign": "^4.0.1",
2523
"pluralize": "^3.0.0",
2624
"request": "^2.72.0",
2725
"server-destroy": "^1.0.1",
28-
"underscore-db": "^0.10.0",
26+
"shortid": "^2.2.6",
27+
"underscore-db": "^0.12.0",
2928
"update-notifier": "^1.0.2",
30-
"yargs": "^4.2.0"
29+
"yargs": "^6.0.0"
3130
},
3231
"devDependencies": {
3332
"babel-cli": "^6.10.1",
34-
"babel-preset-es2015": "^6.9.0",
35-
"cross-env": "^1.0.8",
33+
"babel-preset-es2015": "^6.16.0",
34+
"babel-register": "^6.16.3",
35+
"cross-env": "^2.0.1",
3636
"husky": "^0.11.4",
3737
"mkdirp": "^0.5.1",
38-
"mocha": "^2.2.4",
38+
"mocha": "^3.1.2",
3939
"os-tmpdir": "^1.0.1",
4040
"rimraf": "^2.5.2",
41-
"server-ready": "^0.2.0",
42-
"standard": "^7.1.2",
43-
"supertest": "^1.2.0",
41+
"server-ready": "^0.3.1",
42+
"standard": "^8.3.0",
43+
"supertest": "^2.0.0",
4444
"temp-write": "^2.1.0"
4545
},
4646
"scripts": {
47-
"test": "npm run test:cli && npm run test:server && standard",
48-
"test:cli": "cross-env NODE_ENV=test mocha -R spec test/cli/*.js",
49-
"test:server": "cross-env NODE_ENV=test mocha -R spec test/server/*.js",
47+
"test": "npm run test:cli && npm run test:server && standard --fix",
48+
"test:cli": "npm run build && cross-env NODE_ENV=test mocha test/cli/*.js",
49+
"test:server": "cross-env NODE_ENV=test mocha test/server/*.js",
5050
"start": "node bin",
5151
"prepush": "npm t",
52-
"build": "babel src -d lib"
52+
"build": "babel src -d lib --copy-files"
5353
},
5454
"repository": {
5555
"type": "git",
@@ -76,5 +76,11 @@
7676
"bugs": {
7777
"url": "https://github.com/typicode/json-server/issues"
7878
},
79-
"homepage": "https://github.com/typicode/json-server"
79+
"homepage": "https://github.com/typicode/json-server",
80+
"standard": {
81+
"fix": true,
82+
"env": {
83+
"mocha": true
84+
}
85+
}
8086
}

src/cli/bin.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require('./')()

src/cli/example.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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+
}

src/cli/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
var updateNotifier = require('update-notifier')
2-
var yargs = require('yargs')
3-
var run = require('./run')
4-
var pkg = require('../../package.json')
1+
const updateNotifier = require('update-notifier')
2+
const yargs = require('yargs')
3+
const run = require('./run')
4+
const pkg = require('../../package.json')
55

66
module.exports = function () {
7-
updateNotifier({ pkg: pkg }).notify()
7+
updateNotifier({ pkg }).notify()
88

9-
var argv = yargs
9+
const argv = yargs
1010
.config('config')
1111
.usage('$0 [options] <source>')
1212
.options({

0 commit comments

Comments
 (0)