From 6cd05bfafc6c5a4b3f8e930f4bee8e487563131b Mon Sep 17 00:00:00 2001 From: Falko Habel Date: Tue, 19 Mar 2024 11:46:53 +0100 Subject: [PATCH] bugfixed --- main.go | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/main.go b/main.go index 30ba629..7179ceb 100644 --- a/main.go +++ b/main.go @@ -216,19 +216,17 @@ func handleRequest(w http.ResponseWriter, r *http.Request) { } func main() { - // Define the HTTP handler function - http.HandleFunc("", handleRequest) + // Define the HTTP handler function + http.HandleFunc("/", handleRequest) // This ensures all requests are routed to handleRequest - // Get the port number from the environment variable or use a default value - port := "53184" - if p := os.Getenv("PORT"); p != "" { - port = p - } + // Define the port and ensure listening on localhost only + port := "53184" + address := fmt.Sprintf("localhost:%s", port) // Listen on localhost interface only - // Start the HTTP server - fmt.Printf("Listening :%s...\n", port) - err := http.ListenAndServe(":"+port, nil) - if err != nil { - log.Fatalf("Failed to start server: %v", err) - } -} + // Start the HTTP server + fmt.Printf("Listening on %s...\n", address) + err := http.ListenAndServe(address, nil) + if err != nil { + log.Fatalf("Failed to start server: %v", err) + } +} \ No newline at end of file