Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with Requests to the root route (/) #285

Open
willwill96 opened this issue Apr 2, 2024 · 0 comments
Open

Issues with Requests to the root route (/) #285

willwill96 opened this issue Apr 2, 2024 · 0 comments

Comments

@willwill96
Copy link

willwill96 commented Apr 2, 2024

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)

  1. Pull down the following repo: https://github.com/willwill96/swagger-stats-repro
  2. Run npm install
  3. Run node server.mjs
  4. Make requests to http://localhost:3001 & http://localhost:3001/other
  5. 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

  1. 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.
  2. 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant