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

🤔 Routing example in readme does not work? #411

Closed
panda8z opened this issue May 25, 2020 · 4 comments
Closed

🤔 Routing example in readme does not work? #411

panda8z opened this issue May 25, 2020 · 4 comments
Assignees

Comments

@panda8z
Copy link

panda8z commented May 25, 2020

Issue description
image

@welcome
Copy link

welcome bot commented May 25, 2020

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

@Fenny
Copy link
Member

Fenny commented May 25, 2020

Hi @panda8z, thank you for opening your first issue here!

This is expected behaviour because it will stop at the first match /api/register will match /:name/:age?. You can continue the stack by calling c.Next()

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

	app.Get("/:name/:age?", func(c *fiber.Ctx) {
		fmt.Printf("First route: [name]: %s [age]: %s\n", c.Params("name"), c.Params("age"))
		c.Next() // Continue the stack
	})

	app.Get("/api/*", func(c *fiber.Ctx) {
		fmt.Printf("Last route:  [*]: %s\n", c.Params("*"))
	})

	app.Listen(3000)
	// GET /api/register
	// First route: [name]: api [age]: register
	// Last route:  [*]: register
}

Maybe the example is unclear, and we should edit it :-)

@Fenny Fenny changed the title 🐞 An error example in Readme file 🤔 Routing example in readme does not work? May 25, 2020
@panda8z
Copy link
Author

panda8z commented May 25, 2020

@Fenny
I got it. I’m so thankful for your reply. New code is right.

And I found another error in Static Example

Original:
image

I think here should be reletive path, but every /public is point to the [root]/public.

It should be below:

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

  app.Static("/", "./public")
  // => http://localhost:3000/js/script.js
  // => http://localhost:3000/css/style.css

  app.Static("/prefix", "./public")
  // => http://localhost:3000/prefix/js/script.js
  // => http://localhost:3000/prefix/css/style.css

  app.Static("*", "./public/index.html")
  // => http://localhost:3000/any/path/shows/index/html

  app.Listen(3000)
}

@Fenny
Copy link
Member

Fenny commented May 27, 2020

Nice catch, fixed this in 8303ce8 ~ https://github.com/gofiber/fiber/releases/tag/v1.10.0

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

5 participants