Question description
How to add base URL for whole app ?
Code snippet _Optional_
package main
import "github.com/gofiber/fiber"
func main() {
app := fiber.New()
// .. How to add base URL for whole app ?
// app.setBaseUrl("/api/v1");
app.Get("/", func(c *fiber.Ctx) {
c.Send("Hello, World 馃憢!")
})
}
curl http://localhost/ # 404
curl http://localhost/api/v1/ # 200 "Hello, World 馃憢!"
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
Try app.Group()
i use that but it's seems be anti pattern.
Try
package main
import "github.com/gofiber/fiber"
func main() {
app := fiber.New()
// .. How to add base URL for whole app ?
// app.setBaseUrl("/api/v1");
api := app.Group("/api/v1", func(c *fiber.Ctx) {
c.Send("Hello, World 馃憢!")
c.Next()
})
// app.Get().....
}
func main() {
app := fiber.New()
api := app.Group("/api", handler) // /api
v1 := api.Group("/v1", handler) // /api/v1
v1.Get("/list", handler) // /api/v1/list
v1.Get("/user", handler) // /api/v1/user
v2 := api.Group("/v2", handler) // /api/v2
v2.Get("/list", handler) // /api/v2/list
v2.Get("/user", handler) // /api/v2/user
app.Listen(3000)
}
Most helpful comment