Skip to content

🤗 [Question]: How to check if a handler has been found inside middleware or not #3721

@rugleb

Description

@rugleb

Question Description

Short snippet:

app := fiber.New()
app.Get("/", ...)
app.Get("/users/:id", ...)
app.Use(c *fiber.Ctx) error {
    err := c.Next()
    routePath := c.Route().Path
    println(routePath)
    return err
})

Test case 1: GET /.
In stdout:/. ✅
It's OK, as expected.

Test case 2: GET /users/1.
In stdout:/users/:id. ✅
It's OK, as expected.

Test case 3: GET /unknown.
In stdout: /. 🔥
Why? Why not empty string or /unknown?

So how to check resolved route or not?

Code Snippet (optional)

Upper

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my questions prior to opening this one.
  • I understand that improperly formatted questions may be closed without explanation.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions