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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 Mount sub fiber app on "/" #1842

Closed
lotryas opened this issue Mar 31, 2022 · 4 comments 路 Fixed by #1848
Closed

馃悰 Mount sub fiber app on "/" #1842

lotryas opened this issue Mar 31, 2022 · 4 comments 路 Fixed by #1848

Comments

@lotryas
Copy link

lotryas commented Mar 31, 2022

Fiber version
2.31.0

Issue description
I can access http://localhost:3000/hello but I can't access http://localhost:3000/ for some reason. I get a 404 response from the last handler

Code snippet

package main

import (
    "log"

    "github.com/gofiber/fiber/v2"
)

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

    api := fiber.New()
    api.Get("/", func(c *fiber.Ctx) error { return c.SendString("api") })

    web := fiber.New()
    web.Get("/", func(c *fiber.Ctx) error { return c.SendString("home") })
    web.Get("/hello", func(c *fiber.Ctx) error { return c.SendString("hello") })
    web.Use(func(c *fiber.Ctx) error {
        return fiber.NewError(fiber.StatusNotFound)
    })

    app.Mount("/api", api)
    app.Mount("/", web)

    log.Fatal(app.Listen(":3000"))
}
curl -i http://localhost:3000//
curl -i http://localhost:3000/hello
curl -i http://localhost:3000/
@welcome
Copy link

welcome bot commented Mar 31, 2022

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

@thuri10
Copy link

thuri10 commented Mar 31, 2022

The bug issue raised is not a fiber framework issue but a bug on your code. This is because both app and web variable route definitions calls to the same route "/" causing a conflict on the requests, therefore the response failing. For "/hello" route you are getting result because there is no conflict of routes.

@ReneWerner87
Copy link
Member

ReneWerner87 commented Apr 5, 2022

image

its fixed with the last commit
require github.com/gofiber/fiber/v2 v2.31.1-0.20220405064022-a8f9d4acfb2c

a8f9d4a

@ReneWerner87
Copy link
Member

ReneWerner87 commented Apr 5, 2022

Reason for the bugs:
problem was solved by optimizing the mounting
there the functionality for the root path was broken, because there a trimRight with "/" was used
https://github.com/gofiber/fiber/pull/1749/files

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