fiber icon indicating copy to clipboard operation
fiber copied to clipboard

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

Open darsenault opened this issue 1 year ago • 3 comments

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:

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

darsenault avatar Dec 28 '24 21:12 darsenault

Thanks for opening your first issue here! 🎉 Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

welcome[bot] avatar Dec 28 '24 21:12 welcome[bot]

@darsenault Can you provide a small reproducible example. Thanks

gaby avatar Dec 30 '24 13:12 gaby

Is this still an issue ? @darsenault Could you also provide a small reproducible example so I can take a look at this one. Thanks

aliziyacevik avatar Jan 20 '25 08:01 aliziyacevik