From b6f36d2738fa9b929a58b5c750e64afe351965ec Mon Sep 17 00:00:00 2001 From: James Mills Date: Wed, 25 Mar 2020 07:23:28 +1000 Subject: Add custom CORS config --- app/app.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'app/app.go') diff --git a/app/app.go b/app/app.go index 0ce959c..aa6b129 100644 --- a/app/app.go +++ b/app/app.go @@ -91,6 +91,15 @@ func NewApp(cfg *Config) (*App, error) { http.FileServer(rice.MustFindBox("../static").HTTPBox()), ) r.PathPrefix("/static/").Handler(fsHandler).Methods("GET") + + cors := handlers.CORS( + handlers.AllowedHeaders([]string{"Content-Type"}), + handlers.AllowedOrigins([]string{"*"}), + handlers.AllowCredentials(), + ) + + r.Use(cors) + a.Router = r return a, nil } @@ -114,7 +123,7 @@ func (a *App) Run() error { } buildFeed(a) go startWatcher(a) - return http.Serve(a.Listener, handlers.CORS()(a.Router)) + return http.Serve(a.Listener, a.Router) } func (a *App) render(name string, w http.ResponseWriter, ctx interface{}) { -- cgit v1.2.3