From d55262535115ef57fc3d7b178509f344784cc644 Mon Sep 17 00:00:00 2001 From: kacarmichael Date: Wed, 28 May 2025 01:30:54 -0500 Subject: [PATCH] CORS implementation --- main.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 4f47ea7..151e227 100644 --- a/main.go +++ b/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) + //} + }