aboutsummaryrefslogtreecommitdiff
path: root/cmd/golangorg/server.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2021-11-18 10:55:19 -0500
committerRuss Cox <rsc@golang.org>2021-11-22 16:43:07 +0000
commite77adb1f30f2761cc0e025c1f313b64ffe36a05e (patch)
tree548df37f9dce15d1906fd645fac2d68ae8bdfe5e /cmd/golangorg/server.go
parentceabbb96f3ea960c06beccce4dc2ffacba2e7ec4 (diff)
downloadgo-x-website-e77adb1f30f2761cc0e025c1f313b64ffe36a05e.tar.xz
tour: serve from cmd/golangorg as go.dev/tour
tour.golang.org is the last independent server in this repository and almost the last golang.org domain with user-facing content. (talks.golang.org remains.) We need to keep golang.org/x/website/tour as a runnable binary, but move the logic into internal/tour so it can be used from both the tour binary and cmd/golangorg. After this is deployed, we will need to delete the current tour app from the golang-org project, and then requests for tour.golang.org will default to the main server (cmd/golangorg). This will make the tour available in China for the first time, at golang.google.cn/tour. Change-Id: I0f025d8ae89e12489d26bb3bc380a833eeb57bcc Reviewed-on: https://go-review.googlesource.com/c/website/+/365100 Trust: Russ Cox <rsc@golang.org> Reviewed-by: Jamal Carvalho <jamal@golang.org>
Diffstat (limited to 'cmd/golangorg/server.go')
-rw-r--r--cmd/golangorg/server.go10
1 files changed, 9 insertions, 1 deletions
diff --git a/cmd/golangorg/server.go b/cmd/golangorg/server.go
index 86876da5..de5c0a4d 100644
--- a/cmd/golangorg/server.go
+++ b/cmd/golangorg/server.go
@@ -43,6 +43,7 @@ import (
"golang.org/x/website/internal/proxy"
"golang.org/x/website/internal/redirect"
"golang.org/x/website/internal/short"
+ "golang.org/x/website/internal/tour"
"golang.org/x/website/internal/web"
"golang.org/x/website/internal/webtest"
)
@@ -139,7 +140,7 @@ func NewHandler(contentDir, goroot string) http.Handler {
if contentDir != "" {
contentFS = os.DirFS(contentDir)
} else {
- contentFS = website.Content
+ contentFS = website.Content()
}
var gorootFS fs.FS
@@ -171,6 +172,7 @@ func NewHandler(contentDir, goroot string) http.Handler {
mux.Handle("golang.org/", redirectPrefix("https://go.dev/"))
mux.Handle("blog.golang.org/", redirectPrefix("https://go.dev/blog/"))
mux.Handle("learn.go.dev/", redirectPrefix("https://go.dev/learn/"))
+ mux.Handle("tour.golang.org/", redirectPrefix("https://go.dev/tour/"))
// m.golang.org is an old shortcut for golang.org mail.
// Gmail itself can serve this redirect, but only on HTTP (not HTTPS).
@@ -215,6 +217,10 @@ func NewHandler(contentDir, goroot string) http.Handler {
// Note: Registers for golang.org, go.dev/_, and golang.google.cn.
proxy.RegisterHandlers(mux)
+ if err := tour.RegisterHandlers(mux); err != nil {
+ log.Fatalf("tour: %v", err)
+ }
+
var h http.Handler = mux
h = addCSP(mux)
h = hostEnforcerHandler(h)
@@ -386,6 +392,7 @@ var validHosts = map[string]bool{
"blog.golang.org": true,
"m.golang.org": true,
"tip.golang.org": true,
+ "tour.golang.org": true,
"go.dev": true,
"learn.go.dev": true,
@@ -469,6 +476,7 @@ type linkRewriter struct {
func (r *linkRewriter) WriteHeader(code int) {
loc := r.Header().Get("Location")
+ delete(r.Header(), "Content-Length") // we might change the content
if strings.HasPrefix(loc, "/") {
r.Header().Set("Location", "/"+r.host+loc)
} else if u, _ := url.Parse(loc); u != nil && validHosts[u.Host] {