You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+18-6Lines changed: 18 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -38,7 +38,7 @@ Also, if you make POST, PUT, PATCH or DELETE requests, changes will be automatic
38
38
39
39
## Routes
40
40
41
-
Based on the previous `db.json` file, here are all the available routes. If you need more customization, you can use the project as a [module](https://github.com/typicode/json-server#module).
41
+
Based on the previous `db.json` file, here are all the available routes. If you need to [customize](https://github.com/typicode/json-server#customize), you can use the project as a module.
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.
139
139
140
140
```javascript
141
141
var jsonServer =require('json-server')
142
142
143
-
var server =jsonServer.create() // Returns an Express server
144
-
varrouter=jsonServer.router('db.json') // Returns an Express router
143
+
// Returns an Express server
144
+
varserver=jsonServer.create()
145
145
146
-
server.use(jsonServer.defaults) // logger, static and cors middlewares
147
-
server.use(router) // Mount router on '/'
146
+
// Returns an Express router
147
+
var router =jsonServer.router('db.json')
148
+
149
+
// Default middlewares (logger, static and cors middlewares)
150
+
server.use(jsonServer.defaults)
151
+
152
+
// Add custom routes (optional)
153
+
// You can use rewrite middlewares if you don't want HTTP redirections
154
+
server.use('/custom/route/:id', function (req, res) {
0 commit comments