Merge pull request 'bugfixed' (#18) from readme_file_changes into main

Reviewed-on: Fabelous/GO-Translator#18
This commit is contained in:
Falko Victor Habel 2024-03-19 10:47:16 +00:00
commit a108298c37
1 changed files with 12 additions and 14 deletions

26
main.go
View File

@ -216,19 +216,17 @@ func handleRequest(w http.ResponseWriter, r *http.Request) {
} }
func main() { func main() {
// Define the HTTP handler function // Define the HTTP handler function
http.HandleFunc("", handleRequest) http.HandleFunc("/", handleRequest) // This ensures all requests are routed to handleRequest
// Get the port number from the environment variable or use a default value // Define the port and ensure listening on localhost only
port := "53184" port := "53184"
if p := os.Getenv("PORT"); p != "" { address := fmt.Sprintf("localhost:%s", port) // Listen on localhost interface only
port = p
}
// Start the HTTP server // Start the HTTP server
fmt.Printf("Listening :%s...\n", port) fmt.Printf("Listening on %s...\n", address)
err := http.ListenAndServe(":"+port, nil) err := http.ListenAndServe(address, nil)
if err != nil { if err != nil {
log.Fatalf("Failed to start server: %v", err) log.Fatalf("Failed to start server: %v", err)
} }
} }