try https redir

master
Bel LaPointe 2018-09-30 17:38:47 -06:00
parent 575df05c29
commit e1c7e2bcfd
1 changed files with 9 additions and 1 deletions

10
main.go
View File

@ -7,6 +7,7 @@ import (
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
"strings"
"google.golang.org/appengine" "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") directory := flag.String("d", path.Join(exePath, "public"), "the directory of static file to host")
flag.Parse() 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) log.Printf("Serving %s\n", *directory)