1

I am actually working on building an API in node with express fully defined from a configuration file. But it seems that express don't really like this kind of architechture.

For example my url will be something like

api.domain.com/foo/bar/toto?param1=42

Is it possible to define a route like ?

/.*/.*/.*/

i know that it will be heavier that an api with all route hardcoded in file but i have no choice except generate all the express script by another script

2 Answers2

2

Express supports wildcards:

https://expressjs.com/en/guide/routing.html

You can do something like

router.get('/*', (req, res, next) => {});
Faizuddin Mohammed
  • 4,118
  • 5
  • 27
  • 51
0

try something like that:

app.get('/foo/:foo/:bar/:toto/:param1', function (req, res, next) {
 const res = { foo: req.params.foo,
               bar: req.params.bar,
               toto: req.params.toto,
               param1: req.params.param1,
             };
console.log(res);
});

This question were already asked by the way