Add CORS headers so bus can be accessed cross-origin
This commit is contained in:
parent
7181b6df1b
commit
a5ef82800e
|
@ -83,6 +83,14 @@ func parseArgs() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func corsMiddleware(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
w.Header().Set("Access-Control-Allow-Headers", "*")
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
|
||||
func main() {
|
||||
parseArgs()
|
||||
|
||||
|
@ -109,7 +117,7 @@ func main() {
|
|||
}
|
||||
mb := msgbus.New(&opts)
|
||||
|
||||
http.Handle("/", mb)
|
||||
http.Handle("/", corsMiddleware(mb))
|
||||
http.Handle("/metrics", mb.Metrics().Handler())
|
||||
log.Infof("msgbusd %s listening on %s", msgbus.FullVersion(), bind)
|
||||
log.Fatal(http.ListenAndServe(bind, nil))
|
||||
|
|
2
go.mod
2
go.mod
|
@ -3,7 +3,7 @@ module git.mills.io/prologic/msgbus
|
|||
go 1.17
|
||||
|
||||
require (
|
||||
github.com/gorilla/websocket v1.5.0 // indirect
|
||||
github.com/gorilla/websocket v1.5.0
|
||||
github.com/jpillora/backoff v1.0.0
|
||||
github.com/mitchellh/go-homedir v1.1.0
|
||||
github.com/mmcloughlin/professor v0.0.0-20170922221822-6b97112ab8b3
|
||||
|
|
Loading…
Reference in New Issue