Is there any way to make all the routes that express accepts start with /api without having to define it explicitly?
Current:
this.app.get('/api/endpoint-A', (req, res) => {
return res.send('A');
});
this.app.get('/api/endpoint-B', (req, res) => {
return res.send('B');
});
Objetive:
this.app.get('/endpoint-A', (req, res) => {//https:host.com/api/endpoint-A
return res.send('A');
});
this.app.get('/endpoint-B', (req, res) => {//https:host.com/api/endpoint-B
return res.send('B');
});
Add
app.use('/api/:version/', router);
after you have created a base express router.