uptrace/bunrouter

[ Possible Bug ] bun.Use() function

Opened this issue ยท 0 comments

๐Ÿ’ก The feature or bug you are proposing

As far as i understand the bun.Use() function is supposed to be sort of a middleware.
But when i use it it seems to ignore it, only when i put it inside bun.New(->> here <<--) it works.

๐Ÿ“„ The description of the bug or the logic behind your proposal

I followed the CORS example in this repo, yet it wasn't working.
After a while i decided to made a test function to see if it even goes thru it (the CORS errors weren't making sense)
i found out that i wasn't.
Only when putting it inside the bun.New() it works.

func main() {
...
---------- Works ---------------
router := bunrouter.New(
		bunrouter.Use(newCorsMiddleware()),
	)
---------- Doesn't work ---------------
router := bunrouter.New()
router.Use(newCorsMiddleware())
...
}

func newCorsMiddleware() bunrouter.MiddlewareFunc {
	corsHandler := cors.New(cors.Options{
		AllowedOrigins:   []string{"https://localhost:8888"},
		AllowCredentials: true,
		AllowedHeaders:   []string{"Access-Control-Allow-Origin", "Origin", "EntityCookieFe"},
		AllowedMethods:   []string{"GET", "POST", "OPTIONS"},
		Debug:            true,
	})

	return func(next bunrouter.HandlerFunc) bunrouter.HandlerFunc {
		return bunrouter.HTTPHandler(corsHandler.Handler(next))
	}
}

๐Ÿš€ The expected result

i assume Use() suppose to act as middleware

Thank you in advance.