I have an application which serves file listings.
The application must respond to following routes:
/company/:id
/company/:id/dir
/company/:id/dir/dir
Here /company/:id is a route with no path specified e.g a root directory. I was thinking for something like app.get('/company/:id/:path', ... which obviously doesn't work.
How can I define a route which responds to all of the examples?
Full example
var express = require('express')();
express.use(express.router);
express.get('/company/:id*', function(req, res, next) {
res.json({
id: req.param('id'),
path: req.param(0)
});
});
express.listen(8080);
The only case it doesn't handle is '/company/:id' without a trailing slash.
Maybe use a regex instead of :id.