https://stackoverflow.com/questions/16829803/express-js-route-parameter-with-slashes
https://stackoverflow.com/questions/10020099/express-js-routing-optional-splat-param
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);
This works for /path and /path/foo on express 4, note the *
before ?
.
router.get('/path/:id*?', function(req, res, next) {
res.render('page', { title: req.params.id });
});
Suppose you have this url: /api/readFile/c:/a/a.txt
If you want req.params.path
to be c:
:
'/api/readFile/:path*
If you want req.params.path
to be c:/a/a.txt
:
'/api/readFile/:path([^/]*)'