CORS implementation
This commit is contained in:
parent
aa3e609add
commit
d552625351
24
main.go
24
main.go
@ -6,12 +6,21 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/rs/cors"
|
||||
)
|
||||
|
||||
func main() {
|
||||
sseBroker := NewSSEBroker()
|
||||
checker := NewHealthChecker(sseBroker)
|
||||
|
||||
corsHandler := cors.New(cors.Options{
|
||||
AllowedOrigins: []string{"*"},
|
||||
AllowedMethods: []string{"GET"},
|
||||
AllowedHeaders: []string{"Content-Type"},
|
||||
AllowCredentials: false,
|
||||
}).Handler(http.DefaultServeMux)
|
||||
|
||||
go func() {
|
||||
ticker := time.NewTicker(30 * time.Second)
|
||||
defer ticker.Stop()
|
||||
@ -50,5 +59,18 @@ func main() {
|
||||
})
|
||||
|
||||
log.Println("Serving on :8080")
|
||||
log.Fatal(http.ListenAndServe(":8080", nil))
|
||||
log.Fatal(http.ListenAndServe(":8080", corsHandler))
|
||||
|
||||
//quit := make(chan os.Signal, 1)
|
||||
//signal.Notify(quit, os.Interrupt)
|
||||
//<-quit
|
||||
//
|
||||
//log.Println("Shutdown Server ...")
|
||||
//
|
||||
//ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
//defer cancel()
|
||||
//if err := httpServer.Shutdown(ctx); err != nil {
|
||||
// log.Fatal("Server Shutdown:", err)
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user