Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
3 tasks done
darsenault opened this issue Dec 28, 2024 · 2 comments
Open
3 tasks done

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

darsenault opened this issue Dec 28, 2024 · 2 comments

Comments

@darsenault
Copy link

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.
Copy link

welcome bot commented Dec 28, 2024

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

@gaby
Copy link
Member

gaby commented Dec 30, 2024

@darsenault Can you provide a small reproducible example. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants