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

REST Middleware breaks local auth #262

Closed
petermikitsh opened this Issue Aug 6, 2016 · 5 comments

Comments

Projects
None yet
2 participants
@petermikitsh
Copy link
Contributor

petermikitsh commented Aug 6, 2016

Using an empty REST middleware that calls next() breaks local authentication:

  .configure(rest(function (req, res, next) {
    next();
  }))

vs no middleware:

  .configure(rest())

When the middleware is added, a 404 response is returned. Response content is: Cannot POST /auth/local.

screen shot 2016-08-06 at 2 16 09 pm

@daffl

This comment has been minimized.

Copy link
Member

daffl commented Aug 6, 2016

Is what you want to accomplish the same thing as documented in http://docs.feathersjs.com/rest/readme.html#customizing-the-response-format?

The default formatter can be found in https://github.com/feathersjs/feathers-rest/blob/master/src/index.js#L6.

@petermikitsh

This comment has been minimized.

Copy link
Contributor Author

petermikitsh commented Aug 6, 2016

Yeah, my use case is I need a special endpoint for one of my services that returns an XML document.

I tried defining a formatter right before `app.use('myCustomEndpoint', { get(id) { ... }});`` e.g.,

app
  .config(function (req, res, next) { ... })
  .use('myCustomEndpoint', { ... });

But that wasn't working for me.

@petermikitsh

This comment has been minimized.

Copy link
Contributor Author

petermikitsh commented Aug 6, 2016

Okay, that helped, thanks! I ended up writing my own formatter:

function (req, res, next) {
  if (!res.data) {
    next();
  }
  if (req && req.originalUrl && req.originalUrl.indexOf('myCustomEndpoint') === 0) {
    res.set('Content-Type', 'text/xml');
    res.end(res.data.xml);
  } else {
    res.format({
      'application/json': function () {
        res.json(res.data);
      }
    });
  }
};

A little tricky since it works similarly, but not exactly like, express middleware.

@daffl

This comment has been minimized.

Copy link
Member

daffl commented Aug 6, 2016

It is an Express middleware, I don't think there is any difference. I'm wondering if in your case you really just want to register a formatter after the service (so that the default never gets hit):

app.use('/mycustomservice', myCustomService, function(res, res) {
  res.set('Content-Type', 'text/xml');
  res.end(res.data.xml);
});
@petermikitsh

This comment has been minimized.

Copy link
Contributor Author

petermikitsh commented Aug 7, 2016

Yeah, that is much more what I was looking for since I didn't need to change the global formatter. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.