CORS implementation

This commit is contained in:
kacarmichael 2025-05-28 01:30:54 -05:00
parent aa3e609add
commit d552625351

24
main.go
View File

@ -6,12 +6,21 @@ import (
"net/http" "net/http"
"strings" "strings"
"time" "time"
"github.com/rs/cors"
) )
func main() { func main() {
sseBroker := NewSSEBroker() sseBroker := NewSSEBroker()
checker := NewHealthChecker(sseBroker) checker := NewHealthChecker(sseBroker)
corsHandler := cors.New(cors.Options{
AllowedOrigins: []string{"*"},
AllowedMethods: []string{"GET"},
AllowedHeaders: []string{"Content-Type"},
AllowCredentials: false,
}).Handler(http.DefaultServeMux)
go func() { go func() {
ticker := time.NewTicker(30 * time.Second) ticker := time.NewTicker(30 * time.Second)
defer ticker.Stop() defer ticker.Stop()
@ -50,5 +59,18 @@ func main() {
}) })
log.Println("Serving on :8080") 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)
//}
} }