From e1c7e2bcfd406d7091471c72f155465a3f4811bf Mon Sep 17 00:00:00 2001 From: Bel LaPointe Date: Sun, 30 Sep 2018 17:38:47 -0600 Subject: [PATCH] try https redir --- main.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 9a26d36..cdd9fae 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( "os" "path" "path/filepath" + "strings" "google.golang.org/appengine" ) @@ -21,7 +22,14 @@ func main() { directory := flag.String("d", path.Join(exePath, "public"), "the directory of static file to host") flag.Parse() - http.Handle("/", http.FileServer(http.Dir(*directory))) + http.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.URL.Scheme == "http" || strings.HasPrefix(r.Host, "http:") { + r.URL.Scheme = "https" + http.Redirect(w, r, r.URL.String(), http.StatusTemporaryRedirect) + return + } + http.FileServer(http.Dir(*directory)).ServeHTTP(w, r) + })) log.Printf("Serving %s\n", *directory)