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

[ Possible Bug ] bun.Use() function #101

Open
AlexeyZoz opened this issue Aug 5, 2024 · 0 comments
Open

[ Possible Bug ] bun.Use() function #101

AlexeyZoz opened this issue Aug 5, 2024 · 0 comments

Comments

@AlexeyZoz
Copy link

💡 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.

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

No branches or pull requests

1 participant