From 31b67bb17baa8d1ab9a5d82a19b36b9f9d9f138d Mon Sep 17 00:00:00 2001 From: Chris Gianelloni Date: Sat, 12 Oct 2024 15:51:43 -0400 Subject: [PATCH] fix: cors for htmx (#252) Signed-off-by: Chris Gianelloni --- internal/api/api.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/internal/api/api.go b/internal/api/api.go index b284a44..45e83e8 100644 --- a/internal/api/api.go +++ b/internal/api/api.go @@ -76,7 +76,10 @@ func Start(cfg *config.Config) error { // Catch panics and return a 500 router.Use(gin.Recovery()) // Configure CORS - router.Use(cors.Default()) + corsConfig := cors.DefaultConfig() + corsConfig.AllowAllOrigins = true + corsConfig.AllowHeaders = []string{"hx-current-url","hx-request","hx-target","hx-trigger"} + router.Use(cors.New(corsConfig)) // Access logging accessLogger := logging.GetAccessLogger() skipPaths := []string{} @@ -111,7 +114,7 @@ func Start(cfg *config.Config) error { // Metrics metricsRouter := gin.New() // Configure CORS - metricsRouter.Use(cors.Default()) + metricsRouter.Use(cors.New(corsConfig)) metrics := ginmetrics.GetMonitor() // Set metrics path metrics.SetMetricPath("/")