Answer the question
In order to leave comments, you need to log in
Why is the Go server not opening the page?
Why does this server open the page:
func main() {
fmt.Println("Server is listening port... :900")
http.ListenAndServe("127.0.0.1:900", http.FileServer(http.Dir("F:/Projects/www/domen.com/")))
}
func allRout(w http.ResponseWriter, r *http.Request) {
http.FileServer(http.Dir("F:/Projects/www/domen.com/")).ServeHTTP(w, r)
}
func main() {
fmt.Println("Server (with TLS) is listening port... :600")
var mux = http.NewServeMux()
mux.HandleFunc("/", allRout) // Общий маршрут.
var serv = &http.Server {
Addr: "127.0.0.1:600",
ReadTimeout: 15 * time.Second,
WriteTimeout: 15 * time.Second,
}
log.Fatal(serv.ListenAndServeTLS("F:/Projects/www/domen.com/cert.pem", "F:/Projects/www/domen.com/key.pem"))
}
Answer the question
In order to leave comments, you need to log in
Didn't notice right away, you forgot to tell the server to use your mux
var serv = &http.Server {
Addr: "127.0.0.1:600",
ReadTimeout: 15 * time.Second,
WriteTimeout: 15 * time.Second,
Handler: mux, // <---- здесь
}
func allRout(w http.ResponseWriter, r *http.Request) {
http.FileServer(http.Dir("F:/Projects/www/domen.com/")).ServeHTTP(w, r)
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question