Disabling unused endpoints for new React frontend
All checks were successful
Build Pogdark API / Build Pogdark API (push) Successful in 34s
All checks were successful
Build Pogdark API / Build Pogdark API (push) Successful in 34s
This commit is contained in:
parent
268629a7ac
commit
807bc66acb
22
main.go
22
main.go
@ -149,7 +149,7 @@ func (s *Server) handleConnections(w http.ResponseWriter, r *http.Request) {
|
||||
if err != nil {
|
||||
log.Fatalf("Unable to marshal JSON due to %s", err)
|
||||
}
|
||||
fmt.Printf("Broadcasting ws message to %d clients", s.clients)
|
||||
fmt.Printf("Broadcasting ws message %s to %d clients\n", message, len(s.clients))
|
||||
s.broadcast <- message
|
||||
}
|
||||
}
|
||||
@ -200,7 +200,7 @@ func broadcastExpiredRecords(s *Server, removed string) {
|
||||
log.Println("Error marshalling json:", err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("Broadcasting expiration: %s to %s clients\n", string(msgJSON), len(s.clients))
|
||||
fmt.Printf("Broadcasting expiration: %s to %d clients\n", string(msgJSON), len(s.clients))
|
||||
for client := range s.clients {
|
||||
if err := client.conn.WriteMessage(websocket.TextMessage, msgJSON); err != nil {
|
||||
log.Println("Failed to broadcast update:", err)
|
||||
@ -267,7 +267,8 @@ func fetchAllRecords() (map[string]string, error) {
|
||||
return records, nil
|
||||
}
|
||||
|
||||
func getState(w http.ResponseWriter, r *http.Request) {
|
||||
/*
|
||||
func getState(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
http.Error(w, "Only POST method is allowed", http.StatusMethodNotAllowed)
|
||||
return
|
||||
@ -318,8 +319,8 @@ func getState(w http.ResponseWriter, r *http.Request) {
|
||||
if err != nil {
|
||||
http.Error(w, "Failed to encode response", http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
func setState(w http.ResponseWriter, r *http.Request, s *Server) {
|
||||
if r.Method != http.MethodPost {
|
||||
http.Error(w, "Only POST method is allowed", http.StatusMethodNotAllowed)
|
||||
@ -362,7 +363,8 @@ func setState(w http.ResponseWriter, r *http.Request, s *Server) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
func updateState(w http.ResponseWriter, r *http.Request) {
|
||||
/*
|
||||
func updateState(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodGet {
|
||||
http.Error(w, "Only GET method is allowed", http.StatusMethodNotAllowed)
|
||||
return
|
||||
@ -392,8 +394,8 @@ func updateState(w http.ResponseWriter, r *http.Request) {
|
||||
log.Printf("Error encoding response: %v", err)
|
||||
http.Error(w, "Failed to encode response", http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
func enableCORS(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Access-Control-Allow-Origin", "*") // Allow all origins
|
||||
@ -418,11 +420,11 @@ func main() {
|
||||
|
||||
// Register routes on the mux router
|
||||
router.HandleFunc("/ws", server.handleConnections).Methods("GET")
|
||||
router.HandleFunc("/get", getState).Methods("POST")
|
||||
//router.HandleFunc("/get", getState).Methods("POST")
|
||||
router.HandleFunc("/set", func(w http.ResponseWriter, r *http.Request) {
|
||||
setState(w, r, server)
|
||||
}).Methods("POST")
|
||||
router.HandleFunc("/update", updateState).Methods("GET")
|
||||
//router.HandleFunc("/update", updateState).Methods("GET")
|
||||
corsRouter := enableCORS(router)
|
||||
|
||||
// Start server and other necessary goroutines
|
||||
|
Loading…
Reference in New Issue
Block a user