Skip to content

🐛 [Bug]: Routing - static route broken by route with param #3265

Open
@darsenault

Description

Bug Description

Route with parameter impacting static routes with parameters.

fiberServ.Static("/", "./public") **// OK**

fiberServ.Static("/", "./public") **// OK**
    fiberServ.Get("/home", app.HomeHandler) **// OK**

fiberServ.Static("/", "./public") // BROKEN
    **fiberServ.Get("/entity/:uid", app.EntityHandler) // Breaks static routes!**
    fiberServ.Get("/home", app.HomeHandler) // OK

How to Reproduce

Steps to reproduce the behavior:

  1. Server with the following routes

    fiberServ.Static("/", "./public")
    fiberServ.Get("/entity/:uid", app.EntityHandler)
    fiberServ.Get("/home", app.HomeHandler)

  2. Accessing route /entity/123456789 breaks static routes, adding /entity/ to the static paths.

[Error] Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost:8000/**entity**/css/bulma.min.css

  1. This incorrect behavior does NOT happen with non-parameterized routes like /home. In this case the style sheet in /public/css/bulma.min.css is served properly.

  2. Using a prefix for static does NOT solve the problem. Neither does a trailing / or .
    fiberServ.Static("/public", "./public")
    fiberServ.Static("/public/", "./public")
    fiberServ.Static("/
    ", "./public")

Expected Behavior

So-called regular, with params, routes should not alter static route.

Fiber Version

ithub.com/gofiber/fiber/v2 v2.52.5

Code Snippet (optional)

package main

import "github.com/gofiber/fiber/v3"
import "log"

func main() {
  app := fiber.New()

  // Steps to reproduce

  log.Fatal(app.Listen(":3000"))
}

Checklist:

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

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