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

View File

@@ -28,10 +28,25 @@ func main() {
}
}
// Register handlers with logging middleware
http.HandleFunc("/submit", loggingMiddleware(h.SubmitHandler))
http.HandleFunc("/status", loggingMiddleware(h.StatusHandler))
http.HandleFunc("/result", loggingMiddleware(h.ResultHandler))
// Create a middleware for CORS
corsMiddleware := func(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
// 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"
log.Printf("Server started at %s", port)

Binary file not shown.