Skip to content

Commit 31b67bb

Browse files
authored
fix: cors for htmx (#252)
Signed-off-by: Chris Gianelloni <[email protected]>
1 parent bbe0f8b commit 31b67bb

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

internal/api/api.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ func Start(cfg *config.Config) error {
7676
// Catch panics and return a 500
7777
router.Use(gin.Recovery())
7878
// Configure CORS
79-
router.Use(cors.Default())
79+
corsConfig := cors.DefaultConfig()
80+
corsConfig.AllowAllOrigins = true
81+
corsConfig.AllowHeaders = []string{"hx-current-url","hx-request","hx-target","hx-trigger"}
82+
router.Use(cors.New(corsConfig))
8083
// Access logging
8184
accessLogger := logging.GetAccessLogger()
8285
skipPaths := []string{}
@@ -111,7 +114,7 @@ func Start(cfg *config.Config) error {
111114
// Metrics
112115
metricsRouter := gin.New()
113116
// Configure CORS
114-
metricsRouter.Use(cors.Default())
117+
metricsRouter.Use(cors.New(corsConfig))
115118
metrics := ginmetrics.GetMonitor()
116119
// Set metrics path
117120
metrics.SetMetricPath("/")

0 commit comments

Comments
 (0)