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
Hello,
I wanted to use this plugin and was wondering how the customRoutes is actually generated. From the json-server documentation:
// Add custom routes before JSON Server router
server.get('/echo', function (req, res) {
res.jsonp(req.query)
})
server.use(function (req, res, next) {
if (req.method === 'POST') {
req.body.createdAt = Date.now()
}
// Continue to JSON Server router
next()
})
How would you add this in this plugin? More specifically, I'm looking to alter the GET for every request to wrap it in an object containing some custom information in the response.
@reintroducing currently custom routes added to server instance this way:
if(this.options.customRoutes){
for(var path in this.options.customRoutes) {
var customRoute = this.options.customRoutes[path];
server[customRoute.method.toLocaleLowerCase()](path, customRoute.handler);
}
}
I think this one should be reimplemented, and, unfortunately, I guess for now it is not possible to alter responses for all GET requests, since plugin actually implements only
server.get('/echo', function (req, res) {
res.jsonp(req.query)
})
Include fact that customRoutes doesn't include baseUrl, so full path should be specified, including baseUrl.
The text was updated successfully, but these errors were encountered: