minor changes

This commit is contained in:
2025-03-22 22:10:20 +05:30
parent 1e80c2c121
commit 6426be567a
3 changed files with 19 additions and 5 deletions

Submodule Frontend deleted from 0d629d1da2

View File

@@ -28,10 +28,25 @@ func main() {
} }
} }
// Register handlers with logging middleware // Create a middleware for CORS
http.HandleFunc("/submit", loggingMiddleware(h.SubmitHandler)) corsMiddleware := func(next http.HandlerFunc) http.HandlerFunc {
http.HandleFunc("/status", loggingMiddleware(h.StatusHandler)) return func(w http.ResponseWriter, r *http.Request) {
http.HandleFunc("/result", loggingMiddleware(h.ResultHandler)) // Set CORS headers
w.Header().Set("Access-Control-Allow-Origin", "http://localhost:5173")
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, OPTIONS")
w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
if r.Method == http.MethodOptions {
w.WriteHeader(http.StatusOK)
return
}
next(w, r)
}
}
// Register handlers with logging and CORS middleware
http.HandleFunc("/submit", corsMiddleware(loggingMiddleware(h.SubmitHandler)))
http.HandleFunc("/status", corsMiddleware(loggingMiddleware(h.StatusHandler)))
http.HandleFunc("/result", corsMiddleware(loggingMiddleware(h.ResultHandler)))
port := ":8080" port := ":8080"
log.Printf("Server started at %s", port) log.Printf("Server started at %s", port)

Binary file not shown.