Add custom CORS config
This commit is contained in:
parent
db6322d987
commit
b6f36d2738
2 changed files with 57 additions and 48 deletions
11
app/app.go
11
app/app.go
|
@ -91,6 +91,15 @@ func NewApp(cfg *Config) (*App, error) {
|
||||||
http.FileServer(rice.MustFindBox("../static").HTTPBox()),
|
http.FileServer(rice.MustFindBox("../static").HTTPBox()),
|
||||||
)
|
)
|
||||||
r.PathPrefix("/static/").Handler(fsHandler).Methods("GET")
|
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
|
a.Router = r
|
||||||
return a, nil
|
return a, nil
|
||||||
}
|
}
|
||||||
|
@ -114,7 +123,7 @@ func (a *App) Run() error {
|
||||||
}
|
}
|
||||||
buildFeed(a)
|
buildFeed(a)
|
||||||
go startWatcher(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{}) {
|
func (a *App) render(name string, w http.ResponseWriter, ctx interface{}) {
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue