-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Open
Description
so i have a project that use both nextjs and golang as its frontend and backend. I keep getting blocked from fetching my data because of CORS
this is my cors code on the backend :
import (
"net/http"
"github.com/gin-gonic/gin"
)
func CORSMiddleware() gin.HandlerFunc {
return func(c *gin.Context) {
c.Header("Access-Control-Allow-Origin", "http://localhost:5051")
c.Header("Access-Control-Allow-Credentials", "true")
c.Header("Access-Control-Allow-Headers", "Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, accept, origin, Cache-Control, X-Requested-With")
c.Header("Access-Control-Allow-Methods", "POST, HEAD, PATCH, OPTIONS, GET, PUT, DELETE")
if c.Request.Method == http.MethodOptions {
c.AbortWithStatus(204)
return
}
c.Next()
}
}
i already specify the origin to my localhost domain but it wont work and i also have experimented in my frontend code to put no-cors but still no result. Please help me out
Metadata
Metadata
Assignees
Labels
No labels
