Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feat): add middleware #1630

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

sequencerr
Copy link

diff: main...sequencerr:json-server:feature/add-middleware
credit: https://github.com/typicode/json-server/pull/1625/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5

restoring readme from history: https://github.com/typicode/json-server/blob/v0/README.md?plain=1#L379-L407

json-server/README.md

Lines 379 to 407 in baf0aee

### Add middlewares
You can add your middlewares from the CLI using `--middlewares` option:
```js
// hello.js
module.exports = (req, res, next) => {
res.header('X-Hello', 'World')
next()
}
```
```bash
json-server db.json --middlewares ./hello.js
json-server db.json --middlewares ./first.js ./second.js
```
### 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: "localhost"]
--watch, -w Watch file(s) [boolean]
--routes, -r Path to routes file
--middlewares, -m Paths to middleware files [array]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants