Problem
When using wildcards in route matchers of express, the base route is not added as one of the recorded paths. For example, the following server setup will not record requests to http://localhost:3001:
import express from 'express'
import apiSpec from './swagger.json' assert { type: 'json' };
import swaggerStats from 'swagger-stats'
const app = express()
app.use(swaggerStats.getMiddleware({swaggerSpec: apiSpec, swaggerOnly: true}))
app.get('*', (req, res)=>{
return res.send('hello world')
})
app.listen(3001, ()=>{
console.log('listening')
})
Steps to reproduce
(Using node v18.19.0)
- Pull down the following repo: https://github.com/willwill96/swagger-stats-repro
- Run
npm install
- Run
node server.mjs
- Make requests to
http://localhost:3001 & http://localhost:3001/other
- View
http://localhost:3001/swagger-stats/metrics. Note that the path /other is present for some requests, but / is not.
Expected Behavior
I expect to see path="/" as one of the requests in metrics.
Other notes
- Interestingly, the only way I've been able to get metrics on the root route to work is by removing the wildcard route handler AND switching to
swaggerOnly: false.
- I tried commenting out the code here and it started working as I expected, but I didn't test it thoroughly and don't know if removing it might be breaking something else.
Problem
When using wildcards in route matchers of express, the base route is not added as one of the recorded paths. For example, the following server setup will not record requests to
http://localhost:3001:Steps to reproduce
(Using node v18.19.0)
npm installnode server.mjshttp://localhost:3001&http://localhost:3001/otherhttp://localhost:3001/swagger-stats/metrics. Note that the path/otheris present for some requests, but/is not.Expected Behavior
I expect to see
path="/"as one of the requests in metrics.Other notes
swaggerOnly: false.