diff options
author | Ian Lewis <ianmlewis@gmail.com> | 2019-06-14 21:07:53 -0400 |
---|---|---|
committer | Ian Lewis <ianlewis@google.com> | 2019-06-26 13:07:57 +0800 |
commit | 8d8380564f8284899183a0799bccb8c0b9096566 (patch) | |
tree | e3f79ad759b26dee618d9168d304c3fe4bde350b /cmd/gvisor-website/main.go | |
parent | c1636b150ab0041782634b3d5909ec818675e14d (diff) |
Redirect to the custom domain from appspot.com
Diffstat (limited to 'cmd/gvisor-website/main.go')
-rw-r--r-- | cmd/gvisor-website/main.go | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/cmd/gvisor-website/main.go b/cmd/gvisor-website/main.go index 37b78b7c5..ecae64279 100644 --- a/cmd/gvisor-website/main.go +++ b/cmd/gvisor-website/main.go @@ -97,6 +97,14 @@ func hostRedirectHandler(h http.Handler) http.Handler { http.Redirect(w, r, r.URL.String(), http.StatusMovedPermanently) return } + + if *projectId != "" && r.Host == *projectId+".appspot.com" && *customHost != "" { + // Redirect to the custom domain. + r.URL.Scheme = "https" // Assume https. + r.URL.Host = *customHost + http.Redirect(w, r, r.URL.String(), http.StatusMovedPermanently) + return + } h.ServeHTTP(w, r) }) } @@ -210,6 +218,9 @@ func envFlagString(name, def string) string { var ( addr = flag.String("http", envFlagString("HTTP", ":8080"), "HTTP service address") staticDir = flag.String("static-dir", envFlagString("STATIC_DIR", "static"), "static files directory") + // Uses the standard GOOGLE_CLOUD_PROJECT environment variable set by App Engine. + projectId = flag.String("project-id", envFlagString("GOOGLE_CLOUD_PROJECT", ""), "The App Engine project ID.") + customHost = flag.String("custom-domain", envFlagString("CUSTOM_DOMAIN", "gvisor.dev"), "The application's custom domain.") ) func main() { |