jfromaniello / express-unless

Conditionally add a middleware to express with some common patterns
MIT License
178 stars 27 forks source link

Unless params #19

Closed fecabianchi closed 7 years ago

fecabianchi commented 7 years ago

I have a route for downloading files

router.get('/:id', (req, res) => {
  File
    .findOne({ _id: req.params.id })
    .then(file => res.download(`${__dirname}/../files/${file.fileName}`, `${file.originalName}`))
    .catch(err => res.json(err))
})

i want to use unless on that route but this route have params and unless did not support that.

how can i unless that route?

Thanks in advance.

fecabianchi commented 7 years ago

I manage to make this work with regex

i'll write what i did for help next ppl

first i made the route name more specific

router.get('/download/:id', (req, res) => {
  File
    .findOne({ _id: req.params.id })
    .then(file => res.download(`${__dirname}/../files/${file.fileName}`, `${file.originalName}`))
    .catch(err => res.json(err))
})

then i write a regex for unless

app.use(jwt({ secret:'secret' }).unless({
  path: [
    { url:  /\/api\/file\/download/i },
  ]
}))