|
1 | 1 | # JSON Server [](https://travis-ci.org/typicode/json-server) [](http://badge.fury.io/js/json-server) [](https://gitter.im/typicode/json-server?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) |
2 | 2 |
|
3 | | -> Get a full fake REST API with __zero coding__ in __less than 30 seconds__ (seriously) |
| 3 | +Get a full fake REST API with __zero coding__ in __less than 30 seconds__ (seriously) |
4 | 4 |
|
5 | 5 | Created with :sparkling_heart: for front-end developers who need a quick back-end for prototyping and mocking. |
6 | 6 |
|
@@ -129,26 +129,22 @@ $ json-server index.js |
129 | 129 |
|
130 | 130 | ### Module |
131 | 131 |
|
| 132 | +If you need to add authentication, validation, rewrite or add routes, you can use the project as a module in combination with other Express middlewares. |
| 133 | + |
132 | 134 | ```javascript |
133 | 135 | var jsonServer = require('json-server') |
134 | 136 |
|
135 | | -// Express server |
136 | | -var server = jsonServer.create() |
137 | | - |
138 | | -// Default middlewares (logger, public, cors) |
139 | | -server.use(jsonServer.defaults) |
140 | | - |
141 | | -// Add other Express middlewares if needed (authentication, redirections, ...) |
142 | | -// ... |
| 137 | +var server = jsonServer.create() // Returns an Express server |
| 138 | +var router = jsonServer.router('db.json') // Returns an Express router |
143 | 139 |
|
144 | | - // Express router |
145 | | -server.use(jsonServer.router('db.json')) |
| 140 | +server.use(jsonServer.defaults) // logger, static and cors middlewares |
| 141 | +server.use(router) // Mount router on '/' |
146 | 142 |
|
147 | 143 | server.listen(3000) |
148 | 144 | ``` |
149 | 145 |
|
150 | 146 | For an in-memory database, you can pass an object to `jsonServer.route()`. |
151 | | -Please note also that you can use the `jsonServer.router()` in existing Express servers. |
| 147 | +Please note also that `jsonServer.router()` can be used in existing Express projects. |
152 | 148 |
|
153 | 149 | ### Deployment |
154 | 150 |
|
|
0 commit comments