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?
Use /company/:id*
(note trailing asterisk).
Full example
var express = require('express')();
express.use(express.router);
express.get('/company/:id*', function(req, res, next) {
res.json({
id: req.params['id'],
path: req.params[0]
});
});
express.listen(8080);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With