23 lines
525 B
Go
23 lines
525 B
Go
|
|
package middleware
|
||
|
|
|
||
|
|
import (
|
||
|
|
"github.com/gin-gonic/gin"
|
||
|
|
)
|
||
|
|
|
||
|
|
// CORSMiddleware handles Cross-Origin Resource Sharing
|
||
|
|
func CORSMiddleware() gin.HandlerFunc {
|
||
|
|
return func(c *gin.Context) {
|
||
|
|
// Will be implemented in task 13
|
||
|
|
c.Header("Access-Control-Allow-Origin", "*")
|
||
|
|
c.Header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
|
||
|
|
c.Header("Access-Control-Allow-Headers", "Origin, Content-Type, Authorization")
|
||
|
|
|
||
|
|
if c.Request.Method == "OPTIONS" {
|
||
|
|
c.AbortWithStatus(204)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
c.Next()
|
||
|
|
}
|
||
|
|
}
|