I'm currently refactoring my Node.js application's routing code, and was thinking of using the Router object introduced in Express 4.x. The router needs to capture some parameters in the URL, some of which happen at the very beginning.
At the moment it looks somewhat like this:
var views = require(...); // callback methods for generating each view.
var regexp = ':paramName(...)'; // Regular expression capturing a parameter.
app.get('/' + regexp + '/view_name', views.viewName);
This implementation works as expected, and in the views.viewName method I can retrieve the captured parameter through request.params.paramName.
Now, let's imagine that every valid URL needs to have that form (capturing that parameter). I was thinking of using the Router object like this:
var views = require(...);
var regexp = ':paramName(...)';
var router = express.Router();
router.get('/view_name', views.viewName);
app.use('/' + regexp, router);
This solution (as written) successfully routes the requests towards the views.viewName method, but it seems it fails to capture paramName in the request.
Is there something I'm missing in any of those calls so parameters captured in app.use(...) can be passed on to the request?