From 8b75a1a1566e2ff82c40891b2e7968188dc5e3e3 Mon Sep 17 00:00:00 2001 From: RochoElLocho Date: Sat, 11 Jan 2025 21:01:42 +0100 Subject: [PATCH] https angepasst --- main.go | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/main.go b/main.go index 825b83e..60f0ad9 100644 --- a/main.go +++ b/main.go @@ -20,23 +20,20 @@ func main() { port = "80" } - // HTTP -> HTTPS Weiterleitung - go func() { - log.Fatal(http.ListenAndServe(":80", http.HandlerFunc(redirectToHTTPS))) - }() + // Set up routes + http.HandleFunc("/", handleRoot) + http.HandleFunc("/config", handleConfig) - // Hauptserver für den Reverse Proxy - mux := http.NewServeMux() - mux.HandleFunc("/", handleRoot) - mux.HandleFunc("/config", handleConfig) - mux.HandleFunc("/search", handleSearch) - mux.HandleFunc("/favicon.ico", handleFavicon) + http.HandleFunc("/search", handleSearch) + http.HandleFunc("/favicon.ico", handleFavicon) + // Serve static files from 'public' directory fs := http.FileServer(http.Dir("./public")) - mux.Handle("/public/", http.StripPrefix("/public/", fs)) + http.Handle("/public/", http.StripPrefix("/public/", fs)) - log.Printf("Server läuft auf Port %s (hinter Reverse Proxy)", port) - log.Fatal(http.ListenAndServe(":"+port, mux)) + // Start the server + log.Printf("Server is running at http://0.0.0.0:%s\n", port) + log.Fatal(http.ListenAndServe("0.0.0.0:"+port, nil)) } func handleRoot(w http.ResponseWriter, r *http.Request) { @@ -78,13 +75,6 @@ func handleFavicon(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusNoContent) } -func redirectToHTTPS(w http.ResponseWriter, r *http.Request) { - if r.Header.Get("X-Forwarded-Proto") != "https" { - target := "https://" + r.Host + r.URL.RequestURI() - http.Redirect(w, r, target, http.StatusMovedPermanently) - } -} - func generateSearchUrl(website, query string) string { searchUrls := map[string]string{ // ----- Eletronik ----