Skip to content

Commit

Permalink
README: added documentation for router options (#1290)
Browse files Browse the repository at this point in the history
There was no documentation regarding adding router options when using
json-server as a module. This adds just enough documentation to
hopefully get you started.

Co-authored-by: Sebastian <sebbe@sebbetop.local>
  • Loading branch information
trumtomte and Sebastian committed Feb 5, 2022
1 parent 5f71c09 commit bd4693d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,8 @@ const router = jsonServer.router(path.join(__dirname, 'db.json'))

For an in-memory database, simply pass an object to `jsonServer.router()`.

To add custom options (eg. `foreginKeySuffix`) pass in an object as the second argument to `jsonServer.router('db.json', { foreginKeySuffix: '_id' })`.

Please note also that `jsonServer.router()` can be used in existing Express projects.

#### Custom routes example
Expand Down Expand Up @@ -605,10 +607,12 @@ Returns middlewares used by JSON Server.
* `noCors` disable CORS (default: false)
* `readOnly` accept only GET requests (default: false)

__`jsonServer.router([path|object])`__
__`jsonServer.router([path|object], [options])`__

Returns JSON Server router.

* options (see [CLI usage](#cli-usage))

### Deployment

You can deploy JSON Server. For example, [JSONPlaceholder](http://jsonplaceholder.typicode.com) is an online fake API powered by JSON Server and running on Heroku.
Expand Down

0 comments on commit bd4693d

Please sign in to comment.