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

Update documentation for customRoutes #16

Open
GrafGenerator opened this issue May 16, 2016 · 2 comments
Open

Update documentation for customRoutes #16

GrafGenerator opened this issue May 16, 2016 · 2 comments
Assignees

Comments

@GrafGenerator
Copy link
Owner

Include fact that customRoutes doesn't include baseUrl, so full path should be specified, including baseUrl.

@GrafGenerator GrafGenerator self-assigned this May 16, 2016
@reintroducing
Copy link

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.

Thanks!

@GrafGenerator
Copy link
Owner Author

@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)
})

part of json-server sample above in your comment.

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

No branches or pull requests

2 participants