fastify / fastify/fastify-express
Express wildcard routes override Fastify routes
- Dominant language
- JavaScript
- Stars
- 272
- Forks
- 28
- Avg merge
- 1m
- Merged PRs (30d)
- 1
Description
### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
### Fastify version
4.19.2
### Plugin version
2.3.0
### Node.js version
18.5.0
### Operating system
macOS
### Operating system version (i.e. 20.04, 11.3, 10)
Ventura 13.4
### Description
When mixing a Fastify route and an Express route with a wildcard (`*`), the handler for the Express wildcard route will always be called over the handler for the Fastify route, even if the Fastify route is configured first.
### Steps to Reproduce
```
const Fastify = require('fastify')
const express = require('express')
const router = express.Router()
async function build () {
const fastify = Fastify()
fastify.get('/hello-fastify', function (request, reply) {
reply.send({
hello: 'fastify'
})
})
await fastify.register(require('@fastify/express'))
router.get('/hello-express', (req, res) => {
res.status(201)
res.json({ hello: 'express' })
})
router.get('*', (req, res) => {
res.status(404)
res.json({ msg: 'not found'})
})
fastify.use(router);
return fastify
}
build()
.then(fastify => fastify.listen({ port: 3000 }))
.catch(console.log)
```
```
curl -X GET http://localhost:3000/hello-express
{"hello":"express"}
curl -X GET http://localhost:3000/hello-fastify
{"msg":"not found"}
```
### Expected Behavior
When sending a GET request to the `/hello-fastify` endpoint
```
curl -X GET http://localhost:3000/hello-fastify
```
the handler function provided when calling `fastify.get('/hello-fastify, handler function() {...})` should be called and the response should be
```
{ hello: 'fastify' }
```
.
Contributor guide
Assessment
This issue has not been assessed yet.