Skip to content

Commit

Permalink
fix: cors for htmx (#252)
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Gianelloni <wolf31o2@blinklabs.io>
  • Loading branch information
wolf31o2 authored Oct 12, 2024
1 parent bbe0f8b commit 31b67bb
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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("/")
Expand Down

0 comments on commit 31b67bb

Please sign in to comment.