2025-08-09 15:08:26 +07:00
|
|
|
package middleware
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func CORS() gin.HandlerFunc {
|
2025-08-15 21:17:19 +07:00
|
|
|
return func(c *gin.Context) {
|
2025-08-09 15:08:26 +07:00
|
|
|
c.Header("Access-Control-Allow-Origin", "*")
|
|
|
|
|
c.Header("Access-Control-Allow-Credentials", "true")
|
2025-08-15 21:17:19 +07:00
|
|
|
c.Header("Access-Control-Allow-Headers", "Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, accept, origin, Cache-Control, X-Requested-With, X-Correlation-ID")
|
|
|
|
|
c.Header("Access-Control-Allow-Methods", "POST, OPTIONS, GET, PUT, DELETE, PATCH")
|
|
|
|
|
c.Header("Access-Control-Expose-Headers", "X-Correlation-ID")
|
|
|
|
|
c.Header("Access-Control-Max-Age", "86400")
|
2025-08-09 15:08:26 +07:00
|
|
|
|
|
|
|
|
if c.Request.Method == "OPTIONS" {
|
|
|
|
|
c.AbortWithStatus(204)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c.Next()
|
2025-08-15 21:17:19 +07:00
|
|
|
}
|
2025-08-09 15:08:26 +07:00
|
|
|
}
|