Consider the following code:
import express from 'express';
import { Server, Path, GET, PathParam } from 'typescript-rest';
@Path('/foo')
class FooService {
@Path('bar')
@GET
bar() {
console.log('/foo/bar called');
return 'Bar';
}
@Path(':word')
@GET
customWord(@PathParam('word') word: string): string {
console.log(`/foo/${word} called`);
return word;
}
}
const app: express.Application = express();
Server.buildServices(app);
Here we have two routes: /foo/bar and /foo/:word.
The problem I'm facing is that when I call /foo/bar, both routes are called.
If I'm using vanilla express, this problem does NOT happen. The code:
import express, { Router } from 'express';
const app: express.Application = express();
const router = Router();
router.get('/bar', (req, res) => {
console.log('/foo/bar called');
res.send('bar');
});
router.get('/:word', (req, res) => {
console.log(`/foo/${req.params.word} called`);
res.send(req.params.word);
});
app.use('/foo', router);
app.listen(3000, function () {
console.log('Rest Server listening on port 3000!');
});
I'm using typescript-rest version 3.0.4.
Seems like a bug, but am I doing something wrong?
Consider the following code:
Here we have two routes:
/foo/barand/foo/:word.The problem I'm facing is that when I call
/foo/bar, both routes are called.If I'm using vanilla express, this problem does NOT happen. The code:
I'm using
typescript-restversion3.0.4.Seems like a bug, but am I doing something wrong?