This commit is contained in:
2025-03-22 23:46:49 +05:30
parent 16408e52c7
commit 9d52d42701

View File

@@ -28,13 +28,16 @@ func main() {
} }
} }
// Create a middleware for CORS // Create a middleware for CORS - allow all origins
corsMiddleware := func(next http.HandlerFunc) http.HandlerFunc { corsMiddleware := func(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
// Set CORS headers // Set CORS headers to allow any origin
w.Header().Set("Access-Control-Allow-Origin", "http://localhost:5173") w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, OPTIONS") w.Header().Set("Access-Control-Allow-Methods", "GET, POST, OPTIONS, PUT, DELETE")
w.Header().Set("Access-Control-Allow-Headers", "Content-Type") w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization, X-Requested-With")
w.Header().Set("Access-Control-Max-Age", "3600")
// Handle preflight OPTIONS requests
if r.Method == http.MethodOptions { if r.Method == http.MethodOptions {
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
return return