json-server
Advanced tools
Comparing version 0.8.8 to 0.8.9
# Change Log | ||
## [0.8.9][2016-03-17] | ||
* CLI can now read options from `json-server.json` if present | ||
* CLI option `-c/--config` to point to a different configuration file | ||
## [0.8.8][2016-02-13] | ||
### Fixed | ||
* Fix #233 | ||
## [0.8.7][2016-01-22] | ||
@@ -4,0 +15,0 @@ |
{ | ||
"name": "json-server", | ||
"version": "0.8.8", | ||
"version": "0.8.9", | ||
"description": "Serves JSON files through REST routes.", | ||
@@ -29,6 +29,6 @@ "main": "./src/server/index.js", | ||
"update-notifier": "^0.5.0", | ||
"yargs": "^3.10.0" | ||
"yargs": "^4.2.0" | ||
}, | ||
"devDependencies": { | ||
"husky": "^0.6.1", | ||
"husky": "^0.11.4", | ||
"mocha": "^2.2.4", | ||
@@ -35,0 +35,0 @@ "rimraf": "^2.4.1", |
@@ -40,3 +40,7 @@ # JSON Server [![](https://travis-ci.org/typicode/json-server.svg)](https://travis-ci.org/typicode/json-server) [![](https://badge.fury.io/js/json-server.svg)](http://badge.fury.io/js/json-server) [![](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/typicode/json-server?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) | ||
Also, 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). | ||
Also when doing requests, its good to know that | ||
- 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). | ||
- Your request body JSON should be object enclosed, just like the GET output. (for example `{"name": "Foobar"}`) | ||
- Id values are not mutable. Any `id` value in the body of your PUT or PATCH request wil be ignored. Only a value set in a POST request wil be respected, but only if not already taken. | ||
- A POST, PUT or PATCH request should include a `Content-Type: application/json` header to use the JSON in the request body. Otherwise it wil result in a 200 OK but without changes being made to the data. | ||
@@ -184,2 +188,10 @@ ## Install | ||
### Alternative port | ||
You can start JSON Server on other ports with the `--port` flag: | ||
```bash | ||
$ json-server --watch db.json --port 3004 | ||
``` | ||
### Access from anywhere | ||
@@ -245,2 +257,37 @@ | ||
### CLI usage | ||
``` | ||
json-server [options] <source> | ||
Options: | ||
--config, -c Path to config file [default: "json-server.json"] | ||
--port, -p Set port [default: 3000] | ||
--host, -H Set host [default: "0.0.0.0"] | ||
--watch, -w Watch file(s) [boolean] | ||
--routes, -r Path to routes file | ||
--static, -s Set static files directory | ||
--read-only, --ro Allow only GET requests [boolean] | ||
--no-cors, --nc Disable Cross-Origin Resource Sharing [boolean] | ||
--snapshots, -S Set snapshots directory [default: "."] | ||
--delay, -d Add delay to responses (ms) | ||
--id, -i Set database id property (e.g. _id) [default: "id"] | ||
--quiet, -q Suppress log messages from output [boolean] | ||
--help, -h Show help [boolean] | ||
--version, -v Show version number [boolean] | ||
Examples: | ||
bin db.json | ||
bin file.js | ||
bin http://example.com/db.json | ||
``` | ||
You can also set options in a `json-server.json` configuration file. | ||
```json | ||
{ | ||
"port": 3000 | ||
} | ||
``` | ||
### Module | ||
@@ -247,0 +294,0 @@ |
@@ -11,2 +11,3 @@ var updateNotifier = require('update-notifier') | ||
var argv = yargs | ||
.config('config') | ||
.usage('$0 [options] <source>') | ||
@@ -30,3 +31,3 @@ .options({ | ||
alias: 'r', | ||
description: 'Load routes file' | ||
description: 'Path to routes file' | ||
}, | ||
@@ -62,2 +63,7 @@ static: { | ||
description: 'Suppress log messages from output' | ||
}, | ||
config: { | ||
alias: 'c', | ||
description: 'Path to config file', | ||
default: 'json-server.json' | ||
} | ||
@@ -64,0 +70,0 @@ }) |
@@ -19,3 +19,9 @@ var path = require('path') | ||
delete require.cache[filename] | ||
data = require(filename)() | ||
var dataFn = require(filename) | ||
if (typeof dataFn !== 'function') { | ||
throw new Error('The database is a JavaScript file but the export is not a function.') | ||
} | ||
data = dataFn() | ||
cb(null, data) | ||
@@ -22,0 +28,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
66028
1637
370
+ Addedcamelcase@3.0.0(transitive)
+ Addederror-ex@1.3.2(transitive)
+ Addedfind-up@1.1.2(transitive)
+ Addedget-caller-file@1.0.3(transitive)
+ Addedhosted-git-info@2.8.9(transitive)
+ Addedis-arrayish@0.2.1(transitive)
+ Addedis-core-module@2.15.1(transitive)
+ Addedis-utf8@0.2.1(transitive)
+ Addedload-json-file@1.1.0(transitive)
+ Addedlodash.assign@4.2.0(transitive)
+ Addednormalize-package-data@2.5.0(transitive)
+ Addedparse-json@2.2.0(transitive)
+ Addedpath-exists@2.1.0(transitive)
+ Addedpath-parse@1.0.7(transitive)
+ Addedpath-type@1.1.0(transitive)
+ Addedpify@2.3.0(transitive)
+ Addedread-pkg@1.1.0(transitive)
+ Addedread-pkg-up@1.0.1(transitive)
+ Addedrequire-directory@2.1.1(transitive)
+ Addedrequire-main-filename@1.0.1(transitive)
+ Addedresolve@1.22.8(transitive)
+ Addedset-blocking@2.0.0(transitive)
+ Addedspdx-correct@3.2.0(transitive)
+ Addedspdx-exceptions@2.5.0(transitive)
+ Addedspdx-expression-parse@3.0.1(transitive)
+ Addedspdx-license-ids@3.0.20(transitive)
+ Addedstrip-bom@2.0.0(transitive)
+ Addedsupports-preserve-symlinks-flag@1.0.0(transitive)
+ Addedvalidate-npm-package-license@3.0.4(transitive)
+ Addedwhich-module@1.0.0(transitive)
+ Addedwindow-size@0.2.0(transitive)
+ Addedyargs@4.8.1(transitive)
+ Addedyargs-parser@2.4.1(transitive)
- Removedcamelcase@2.1.1(transitive)
- Removedwindow-size@0.1.4(transitive)
- Removedyargs@3.32.0(transitive)
Updatedyargs@^4.2.0