-
-
Notifications
You must be signed in to change notification settings - Fork 751
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
Be able to create custom routes #93
Comments
I'm not sure the prefix is necessary. Why couldn't you just do app.use('/api/users', UserService); Or create a separate app and use it on a different route (as done with the new Testee):
As for the content type, Express does allow REST content negotiation, for Feathers like: app.configure(feathers.rest(function restFormatter(req, res) {
res.format({
'text/plain': function() {
res.end('The todo is: ' + res.data.description);
},
'application/json': function() {
res.json(res.data);
}
});
})); I don't think you can use file name extensions this way but setting the |
Very clever Dave 😉. Totally didn't think of that one. As for content negotiation say I want to render out a specific template. For example I hit the |
I would keep that separate from the service though. In the negotiator it would be app.configure(feathers.rest(function restFormatter(req, res) {
res.format({
'text/html': function() {
var template = req.url;
res.render('/views/' + template, res.data);
},
'application/json': function() {
res.json(res.data);
}
});
})); The view information could also be added with a custom middleware: app.use('/users', function(req, res, next) {
req.view = 'views/user.jade';
next();
}, UserService); |
Yep that works pretty well and what I had tried. For some reason my Regardless, the solution is good but it gets complicated when you have urls like Otherwise you end up writing some janky logic to determine which template should be rendered based on the route path. This could get really complicated if you have stuff like |
@daffl In the case where you have
do configurations from
, do we still need to do the same for Thanks! |
I don't think so. Every Express application has its individual middleware stack. The easiest way is probably to put common middleware into a separate function setup() {
var app = this;
app.configure(feathers.rest())
.use(bodyParser.json())
}
app.configure(setup);
api.configure(setup); |
Yep, just tried leaving out configuration for the Thanks for the quick response! |
I think we can close this issue? If there is still things to think about I'd put them in a new one. I worked with a Feathers app that had some static pages and didn't run into any hard problems connecting services and rendering static pages. |
* Update to new plugin infrastructure and npm scope (#92) * Update to new plugin infrastructure and npm scope * Update debug dependency * Update year and release script * Prepare prerelease * 3.0.0-pre.1 * Updating changelog
* Update to new plugin infrastructure and npm scope (#92) * Update to new plugin infrastructure and npm scope * Update debug dependency * Update year and release script * Prepare prerelease * 3.0.0-pre.1 * Updating changelog
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue with a link to this issue for related bugs. |
I would like to be able to specify what mime types are supported via rest:
and also create namespaced routes:
Similar idea to #86 but I don't think using the
.setup()
method is elegant or efficient.The text was updated successfully, but these errors were encountered: