From 2edd304c349b5a8ef6197bfbd6be654c7cbb315c Mon Sep 17 00:00:00 2001 From: Kelvin Ly Date: Sun, 28 Jul 2019 08:59:17 -0400 Subject: [PATCH] Switch for manual forwarding to reverse proxy; this should be websocket compatible --- main.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 2e9460b..030d02d 100644 --- a/main.go +++ b/main.go @@ -11,6 +11,8 @@ import ( "fmt" "log" "net/http" + "net/http/httputil" + "net/url" "os" "os/exec" "path" @@ -327,7 +329,13 @@ func startServer(srv *http.Server) { serveMux := http.NewServeMux() if !*devmode { - serveMux.HandleFunc("dev."+DOMAIN_NAME+"/", forwardRequest(8081, "http")) + //serveMux.HandleFunc("dev."+DOMAIN_NAME+"/", forwardRequest(8081, "http")) + url, err := url.Parse("http://localhost:8081") + if err != nil { + log.Fatalf("unable to parse reverse proxy path: %v", err) + return + } + serveMux.Handle("dev."+DOMAIN_NAME+"/", httputil.NewSingleHostReverseProxy(url)) } serveMux.HandleFunc("/", rootHandler) //serveMux.Handle("/certbot/", http.StripPrefix("/certbot/", http.FileServer(http.Dir("./certbot-tmp")))) @@ -407,7 +415,14 @@ func startRedirectServer(srv *http.Server) { serveMux := http.NewServeMux() // copied from https://gist.github.com/d-schmidt/587ceec34ce1334a5e60 if !*devmode { - serveMux.HandleFunc("dev."+DOMAIN_NAME+"/", forwardRequest(8081, "http")) + //serveMux.HandleFunc("dev."+DOMAIN_NAME+"/", forwardRequest(8081, "http")) + url, err := url.Parse("http://localhost:8081") + if err != nil { + log.Fatalf("unable to parse reverse proxy path: %v", err) + return + } + serveMux.Handle("dev."+DOMAIN_NAME+"/", httputil.NewSingleHostReverseProxy(url)) + } serveMux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {