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

GoBuffalo support #46

Closed
danikarik opened this issue Jan 17, 2018 · 4 comments
Closed

GoBuffalo support #46

danikarik opened this issue Jan 17, 2018 · 4 comments

Comments

@danikarik
Copy link

Hi!

I'm trying to use CORS middleware with Buffalo.
I saw code snippet in the issue #609.

It works, but after OPTIONS call log prints warning "multiple response.WriteHeader calls":

[cors] 2018/01/17 15:35:08 Handler: Preflight request
[cors] 2018/01/17 15:35:08   Preflight response headers: map[Vary:[Origin Access-Control-Request-Method Access-Control-Request-Headers] Access-Control-Allow-Origin:[http://localhost:4200] Access-Control-Allow-Methods:[POST] Access-Control-Allow-Headers:[Content-Type] Access-Control-Allow-Credentials:[true]]
2018/01/17 15:35:08 http: multiple response.WriteHeader calls
[cors] 2018/01/17 15:35:08 Handler: Actual request
[cors] 2018/01/17 15:35:08   Actual response added headers: map[Access-Control-Allow-Credentials:[true] Vary:[Origin] Access-Control-Allow-Origin:[http://localhost:4200]]

Could you suggest me, how to fix this warning?

My code:

func App() *buffalo.App {
	if app == nil {
		app = buffalo.New(buffalo.Options{
			Env:          ENV,
			SessionStore: sessions.NewCookieStore([]byte(SECRET)),
			SessionName:  "sessionid",
		})

		// Set the request content type to JSON
		app.Use(middleware.SetContentType("application/json"))

		if ENV == "development" {
			app.Use(middleware.ParameterLogger)
			app.PreWares = []buffalo.PreWare{cors.New(cors.Options{
				AllowedOrigins:   []string{"*"},
				AllowedMethods:   []string{"GET", "POST", "PUT", "DELETE"},
				AllowedHeaders:   []string{"Content-Type", "Cookie"},
				AllowCredentials: true,
				Debug:            true,
			}).Handler}
		}

		// Set custom error response
		// SOME STAFF

		app.GET("/", HomeHandler)

		app.POST("/session", AuthLogin)

		auth := app.Group("/")
		auth.Use(AuthRequired)
		auth.DELETE("/session", AuthLogout)
		auth.GET("/session", AuthSession)
	}

	return app
}
@rs
Copy link
Owner

rs commented Jan 17, 2018

Try setting OptionsPassthrough to true.

@danikarik
Copy link
Author

Doing that, getting 405 Method Not Allowed on OPTIONS call.

@rs
Copy link
Owner

rs commented Jan 23, 2018

I just added a minimal example with Buffalo: 1c02c2b

I can't reproduce the issue. Please, augment my example with the necessary code that triggers the issue.

@danikarik
Copy link
Author

Hi! Issue was on Buffalo package and it occurs on non GET methods like POST, PUT. etc.
There is link #861.

Closing issue. Thanks!

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

2 participants