lukeed / polka

A micro web server so fast, it'll make you dance! :dancers:

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Original path pattern available to middleware?

saibotsivad opened this issue Β· comments

Is there a way to grab the original pattern off the request in the middleware? Hacky solutions accepted. πŸ˜…

I want the middleware to know what path was matched, so something like this

import polka from 'polka'

const app = polka()

app.use((req, res, next) => {
    console.log(req.matchedPath) // => "/users/:id"
})

app.get('/users/:id', (req, res) => {
    // do whatever
})

After more digging, I realize I opened this as a Trouter issue first, which is where this discussion would need to start.