https angepasst

This commit is contained in:
Domenik Rath 2025-01-11 21:01:42 +01:00
parent ff9f9847b4
commit 8b75a1a156

30
main.go
View File

@ -20,23 +20,20 @@ func main() {
port = "80" port = "80"
} }
// HTTP -> HTTPS Weiterleitung // Set up routes
go func() { http.HandleFunc("/", handleRoot)
log.Fatal(http.ListenAndServe(":80", http.HandlerFunc(redirectToHTTPS))) http.HandleFunc("/config", handleConfig)
}()
// Hauptserver für den Reverse Proxy http.HandleFunc("/search", handleSearch)
mux := http.NewServeMux() http.HandleFunc("/favicon.ico", handleFavicon)
mux.HandleFunc("/", handleRoot)
mux.HandleFunc("/config", handleConfig)
mux.HandleFunc("/search", handleSearch)
mux.HandleFunc("/favicon.ico", handleFavicon)
// Serve static files from 'public' directory
fs := http.FileServer(http.Dir("./public")) 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) // Start the server
log.Fatal(http.ListenAndServe(":"+port, mux)) 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) { func handleRoot(w http.ResponseWriter, r *http.Request) {
@ -78,13 +75,6 @@ func handleFavicon(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNoContent) 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 { func generateSearchUrl(website, query string) string {
searchUrls := map[string]string{ searchUrls := map[string]string{
// ----- Eletronik ---- // ----- Eletronik ----