-
Notifications
You must be signed in to change notification settings - Fork 117
REST Middleware breaks local auth #262
Comments
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. |
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.,
But that wasn't working for me. |
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. |
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);
}); |
Yeah, that is much more what I was looking for since I didn't need to change the global formatter. Thanks again! |
Using an empty REST middleware that calls next() breaks local authentication:
vs no middleware:
When the middleware is added, a
404
response is returned. Response content is:Cannot POST /auth/local
.The text was updated successfully, but these errors were encountered: