-
-
Notifications
You must be signed in to change notification settings - Fork 17.3k
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
app.use('/:param', paramApp) not supported #696
Comments
nope, that would just be a regular route, aka |
I think this represents an integral feature for RESTful app design, ie a pattern of /:resource_id/action. In this case, mounting an app as a resource seems more natural than not. I can give a few examples from just our apps:
and so on. We are currently using
but the following would not only be more elegant, but useful
What do you think? |
of course, but you start with the basics, allowing you to build up to anything. Starting with a high-level api is not the way to go, which like I mentioned is where express-resource comes into play etc, at it's core it's nothing more than a callback for a http method/url |
Thank you for express-resource reference, I didn't know about it. Will check it out. |
this issue just bit me pretty hard. i expected |
it's something we could consider for the next majors. Once node has the stuff in Connect's patch.js I wanted to consider removing .use() and the dispatcher from Connect, moving that into Express would allow Connect's components to work with any node app, then .use() could be part of Express and utilize some of the routing code if we need to. There's a lot we could clean up, |
any updates here? it would be useful to have this working. |
Same question, I need to mount an existing application to a variable mount point. I suppose I could go with |
can you guys provide an example showing why you need to mount the app under the variable mount point and not just put the variable inside the app? Also, please try this on master and see if it works there using a Router. |
+1 for use-case, can't wrap my head around a reason for this. |
I don't think it'll work anyways since every route overwrites the parameters. |
Here's an example: I have my API broken down into subapps (each resource is basically a subapp) so in my main app.js I have
This way I can auto-load the farm resource in the farms module and then hand it over to the fields module with the farm already loaded, and the fields can handle the rest of the request as if /fields was a top level resource. Right now my /fields routes are registered in /lib/farms like this: |
Here is a sample app that fails against var express = require('express');
// fields get mounted under /farms/:id/
var fields = new express.Router();
fields.param('id', function(req, res, next, id) {
req.field = {
farm: req.farm,
id: id,
name: 'foobar'
};
next();
});
fields.get('/', function(req, res, next) {
res.json([]);
});
fields.get('/:id', function(req, res, next) {
res.json(req.field);
});
// farms is mounted under /farms
var farms = new express.Router();
farms.param('id', function(req, res, next, id) {
req.farm = {
id: id,
name: 'foobar'
};
next();
});
farms.use('/:id/fields', fields.middleware);
farms.get('/:id', function(req, res, next) {
res.json(req.farm);
});
var app = express();
app.use('/farms', farms.middleware);
app.listen('3000');
// call to /farms/123/fields does not work I think this should work and don't see a reason why the parameter handling is being done the way it is currently per route versus at the router level. I will be taking a look at this. |
It seems that a use case where an app would be mounted onto a URL with arguments in not currently supported.
The text was updated successfully, but these errors were encountered: