edit cors

This commit is contained in:
areeqakbr 2025-02-20 11:21:45 +07:00
parent d660a030e7
commit a5fdd64877
1 changed files with 6 additions and 1 deletions

View File

@ -6,7 +6,12 @@ import (
func CORSMiddleware() gin.HandlerFunc {
return func(c *gin.Context) {
c.Writer.Header().Set("Access-Control-Allow-Origin", "http://localhost:5173")
origin := c.Request.Header.Get("Origin") // Get the request origin
if origin != "" {
c.Writer.Header().Set("Access-Control-Allow-Origin", origin)
}
c.Writer.Header().Set("Access-Control-Allow-Credentials", "true")
c.Writer.Header().Set("Access-Control-Allow-Headers", "Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, accept, origin, Cache-Control, X-Requested-With")
c.Writer.Header().Set("Access-Control-Allow-Methods", "POST, OPTIONS, GET, PUT, DELETE")