Skip to content

🐛 [Bug]: Static server in sub app does not work #3104

Open
@lephattan

Description

@lephattan

Question Description

I am trying to set app a static server in a sub app, but it does not seem to work.
The problem can be reproduced with the snippet below.

Project struture:

tree .
#.
#├── go.mod
#├── go.sum
#├── main.go
#└── public
#    └── test.txt

Tests:

cat public/test.txt
# test

curl http://127.0.0.1:3000/
# Hello, world!%

curl http://127.0.0.1:3000/public/test.txt
# test

curl http://127.0.0.1:3000/subApp
# Hello from subApp%

curl http://127.0.0.1:3000/subApp/public/test.txt
# Cannot GET /subApp/public/test.txt%

Code Snippet (optional)

package main

import (
	"github.com/gofiber/fiber/v2"
	"github.com/gofiber/fiber/v2/middleware/logger"
)

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

	app.Static("/public", "./public")

	app.Get("/", func(c *fiber.Ctx) error {
		return c.SendString("Hello, world!")
	})

	subApp := fiber.New()
	subApp.Use(logger)

	subApp.Static("/public", "./public")

	subApp.Get("/", func(c *fiber.Ctx) error {
		return c.SendString("Hello from subApp")
	})

	app.Mount("/subApp", subApp)
	app.Listen(":3000")
}

Checklist:

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

Metadata

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