Files
kontor/kontor-gin/pkg/middleware/cors.go
T
Thomas Peetz 044da5353a
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 5s
add templates for kontor-gin
2026-09-22 19:19:51 +02:00

24 lines
564 B
Go

package middleware
import (
"net/http"
"github.com/gin-gonic/gin"
)
// corsMiddleware adds CORS headers for cross-origin requests
func CorsMiddleware(c *gin.Context) {
c.Header("Access-Control-Allow-Origin", "*")
c.Header("Access-Control-Allow-Methods", "GET, POST, PUT, PATCH, DELETE, OPTIONS")
c.Header("Access-Control-Allow-Headers", "Content-Type, Authorization")
c.Header("Access-Control-Allow-Credentials", "true")
// Handle preflight requests
if c.Request.Method == "OPTIONS" {
c.AbortWithStatus(http.StatusNoContent)
return
}
c.Next()
}