mirror of
https://github.com/typicode/json-server.git
synced 2025-07-27 20:23:34 +08:00
Update README.md
This commit is contained in:
11
README.md
11
README.md
@ -254,19 +254,20 @@ Now you can access resources using additional routes.
|
|||||||
/blog/posts/1/show
|
/blog/posts/1/show
|
||||||
```
|
```
|
||||||
|
|
||||||
### Use middlewares
|
### Add middlewares
|
||||||
|
|
||||||
You can use express middlewares with `--middlewares` option
|
You can add your middlewares from the CLI using `--middlewares` option:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// middlewares.js
|
// first.js
|
||||||
module.exports = function (req, res, next) {
|
module.exports = function (req, res, next) {
|
||||||
res.Header('X-Hello', 'World')
|
res.Header('X-Hello', 'World')
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
json-server db.json --middlewares middlewares.js
|
json-server db.json --middlewares ./hello.js
|
||||||
|
json-server db.json --middlewares ./first.js ./second.js
|
||||||
```
|
```
|
||||||
|
|
||||||
### CLI usage
|
### CLI usage
|
||||||
@ -280,7 +281,7 @@ Options:
|
|||||||
--host, -H Set host [default: "0.0.0.0"]
|
--host, -H Set host [default: "0.0.0.0"]
|
||||||
--watch, -w Watch file(s) [boolean]
|
--watch, -w Watch file(s) [boolean]
|
||||||
--routes, -r Path to routes file
|
--routes, -r Path to routes file
|
||||||
--middlewares, -m Path to middlewares file
|
--middlewares, -m Paths to middleware files [array]
|
||||||
--static, -s Set static files directory
|
--static, -s Set static files directory
|
||||||
--read-only, --ro Allow only GET requests [boolean]
|
--read-only, --ro Allow only GET requests [boolean]
|
||||||
--no-cors, --nc Disable Cross-Origin Resource Sharing [boolean]
|
--no-cors, --nc Disable Cross-Origin Resource Sharing [boolean]
|
||||||
|
Reference in New Issue
Block a user