camweb: migrate to perkeep.org as the production domain

issue #981

Change-Id: I0355e2ee7cf36440996f0bd00c1f2ff5bfce213d
This commit is contained in:
mpl 2017-12-08 21:33:44 +01:00
parent 29693e2cc5
commit 6460c449f0
1 changed files with 14 additions and 10 deletions

View File

@ -65,6 +65,7 @@ import (
const ( const (
defaultAddr = ":31798" // default webserver address defaultAddr = ":31798" // default webserver address
prodBucket = "camlistore-website-resource" // where we store misc resources for the production website prodBucket = "camlistore-website-resource" // where we store misc resources for the production website
prodDomain = "perkeep.org"
) )
var h1TitlePattern = regexp.MustCompile(`<h1>([^<]+)</h1>`) var h1TitlePattern = regexp.MustCompile(`<h1>([^<]+)</h1>`)
@ -467,12 +468,13 @@ func (h *redirectRootHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request)
} }
host := strings.ToLower(r.Host) host := strings.ToLower(r.Host)
if host == "www.camlistore.org" || (inProd && r.TLS == nil) { if host == "www.camlistore.org" || host == "camlistore.org" ||
host == "www."+prodDomain || (inProd && r.TLS == nil) {
if inStaging { if inStaging {
http.Redirect(rw, r, "https://"+stagingHostname+r.URL.RequestURI(), http.StatusFound) http.Redirect(rw, r, "https://"+stagingHostname+r.URL.RequestURI(), http.StatusFound)
return return
} }
http.Redirect(rw, r, "https://camlistore.org"+r.URL.RequestURI(), http.StatusFound) http.Redirect(rw, r, "https://"+prodDomain+r.URL.RequestURI(), http.StatusFound)
return return
} }
h.Handler.ServeHTTP(rw, r) h.Handler.ServeHTTP(rw, r)
@ -539,7 +541,7 @@ func gceDeployHandler(prefix string) (*gce.DeployHandler, error) {
if inStaging { if inStaging {
hostPort = stagingHostname + ":443" hostPort = stagingHostname + ":443"
} else { } else {
hostPort = "camlistore.org:443" hostPort = prodDomain + ":443"
} }
} else { } else {
addr := *httpsAddr addr := *httpsAddr
@ -617,6 +619,7 @@ func setProdFlags() {
*flagChromeBugRepro = true *flagChromeBugRepro = true
*httpAddr = ":80" *httpAddr = ":80"
*httpsAddr = ":443" *httpsAddr = ":443"
// TODO(mpl): investigate why this proxying does not seem to be working (we end up on https://camlistore.org).
buildbotBackend = "https://travis-ci.org/camlistore/camlistore" buildbotBackend = "https://travis-ci.org/camlistore/camlistore"
buildbotHost = "build.camlistore.org" buildbotHost = "build.camlistore.org"
*gceLogName = "camweb-access-log" *gceLogName = "camweb-access-log"
@ -982,7 +985,7 @@ func serveHTTPS(httpServer *http.Server) error {
*httpsServer = *httpServer *httpsServer = *httpServer
httpsServer.Addr = *httpsAddr httpsServer.Addr = *httpsAddr
cacheDir := autocert.DirCache("letsencrypt.cache") cacheDir := autocert.DirCache("letsencrypt.cache")
var domain string var hostPolicy autocert.HostPolicy
if !inProd { if !inProd {
if *tlsCertFile != "" && *tlsKeyFile != "" { if *tlsCertFile != "" && *tlsKeyFile != "" {
return httpsServer.ListenAndServeTLS(*tlsCertFile, *tlsKeyFile) return httpsServer.ListenAndServeTLS(*tlsCertFile, *tlsKeyFile)
@ -995,18 +998,19 @@ func serveHTTPS(httpServer *http.Server) error {
if err != nil { if err != nil {
return err return err
} }
domain = host hostPolicy = autocert.HostWhitelist(host)
} else { } else {
if inStaging { if inStaging {
domain = stagingHostname hostPolicy = autocert.HostWhitelist(stagingHostname)
} else { } else {
domain = "camlistore.org" hostPolicy = autocert.HostWhitelist(prodDomain, "www."+prodDomain,
"www.camlistore.org", "camlistore.org")
} }
cacheDir = autocert.DirCache(prodLECacheDir) cacheDir = autocert.DirCache(prodLECacheDir)
} }
m := autocert.Manager{ m := autocert.Manager{
Prompt: autocert.AcceptTOS, Prompt: autocert.AcceptTOS,
HostPolicy: autocert.HostWhitelist(domain), HostPolicy: hostPolicy,
Cache: cacheDir, Cache: cacheDir,
} }
if *adminEmail != "" { if *adminEmail != "" {
@ -1094,7 +1098,7 @@ func gerritRedirect(w http.ResponseWriter, r *http.Request) {
func releaseRedirect(w http.ResponseWriter, r *http.Request) { func releaseRedirect(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/dl" || r.URL.Path == "/dl/" { if r.URL.Path == "/dl" || r.URL.Path == "/dl/" {
http.Redirect(w, r, "https://camlistore.org/download/", http.StatusFound) http.Redirect(w, r, "https://"+prodDomain+"/download/", http.StatusFound)
return return
} }
dest := "https://storage.googleapis.com/camlistore-release/" + strings.TrimPrefix(r.URL.Path, "/dl/") dest := "https://storage.googleapis.com/camlistore-release/" + strings.TrimPrefix(r.URL.Path, "/dl/")
@ -1153,7 +1157,7 @@ const (
toHyperlink = `<a href="$1$2">$1$2</a>` toHyperlink = `<a href="$1$2">$1$2</a>`
) )
var camliURLPattern = regexp.MustCompile(`(https?://camlistore.org)([a-zA-Z0-9\-\_/]+)?`) var camliURLPattern = regexp.MustCompile(`(https?://` + prodDomain + `)([a-zA-Z0-9\-\_/]+)?`)
func errHandler(w http.ResponseWriter, r *http.Request) { func errHandler(w http.ResponseWriter, r *http.Request) {
errString := strings.TrimPrefix(r.URL.Path, errPattern) errString := strings.TrimPrefix(r.URL.Path, errPattern)