try https redir
parent
575df05c29
commit
e1c7e2bcfd
10
main.go
10
main.go
|
|
@ -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)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue