minor changes
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user