diff options
| author | Russ Cox <rsc@golang.org> | 2021-11-22 20:23:51 -0500 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2021-11-30 18:10:09 +0000 |
| commit | 7f5094fc5c11a68ee7b8614f34acbd02923866e5 (patch) | |
| tree | 72a1c9632bc4f72de1d7a0238b7ac196c12b6bb5 /cmd/golangorg/server.go | |
| parent | b0a4f90f1261c2bab5cf75edc5b91e6f5eb7222b (diff) | |
| download | go-x-website-7f5094fc5c11a68ee7b8614f34acbd02923866e5.tar.xz | |
cmd/golangorg: add support for multiple play backends
This lets people choose between the release version of Go (play.golang.org)
and the dev branch version (gotipplay.golang.org).
After CL 365854 goes live, it will offer Go 1.17, Go 1.16, and Go dev branch.
Change-Id: I7480a0cb4f1b09636f5728c41af507aac5a72026
Reviewed-on: https://go-review.googlesource.com/c/website/+/366056
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jamal Carvalho <jamal@golang.org>
Diffstat (limited to 'cmd/golangorg/server.go')
| -rw-r--r-- | cmd/golangorg/server.go | 30 |
1 files changed, 6 insertions, 24 deletions
diff --git a/cmd/golangorg/server.go b/cmd/golangorg/server.go index adcae977..eda65ef1 100644 --- a/cmd/golangorg/server.go +++ b/cmd/golangorg/server.go @@ -40,7 +40,7 @@ import ( "golang.org/x/website/internal/history" "golang.org/x/website/internal/memcache" "golang.org/x/website/internal/pkgdoc" - "golang.org/x/website/internal/proxy" + "golang.org/x/website/internal/play" "golang.org/x/website/internal/redirect" "golang.org/x/website/internal/short" "golang.org/x/website/internal/talks" @@ -206,12 +206,12 @@ func NewHandler(contentDir, goroot string) http.Handler { if err != nil { log.Fatalf("newSite golang.google.cn: %v", err) } - siteMux.Handle("/play/", playHandler(godevSite)) - siteMux.Handle("golang.google.cn/play/", playHandler(chinaSite)) dl.RegisterHandlers(siteMux, godevSite, "", datastoreClient, memcacheClient) dl.RegisterHandlers(siteMux, chinaSite, "golang.google.cn", datastoreClient, memcacheClient) mux.Handle("/", siteMux) + play.RegisterHandlers(mux, godevSite, chinaSite) + mux.Handle("/explore/", http.StripPrefix("/explore/", redirectPrefix("https://pkg.go.dev/"))) if err := blog.RegisterFeeds(mux, "", godevSite); err != nil { log.Fatalf("blog: %v", err) @@ -226,9 +226,6 @@ func NewHandler(contentDir, goroot string) http.Handler { appEngineSetup(mux) } - // Note: Registers for golang.org, go.dev/_, and golang.google.cn. - proxy.RegisterHandlers(mux) - // Note: Using godevSite (non-China) for global mux registration because there's no sharing in talks. // Don't need the hassle of two separate registrations for different domains in siteMux. if err := talks.RegisterHandlers(mux, godevSite, contentFS); err != nil { @@ -245,24 +242,6 @@ func NewHandler(contentDir, goroot string) http.Handler { return h } -func playHandler(site *web.Site) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if r.URL.Path == "/play/p" || r.URL.Path == "/play/p/" { - http.Redirect(w, r, "/play/", http.StatusFound) - return - } - if r.Host == "golang.google.cn" && strings.HasPrefix(r.URL.Path, "/play/p/") { - site.ServeError(w, r, errors.New("Sorry, but shared playground snippets are not visible in China.")) - return - } - site.ServePage(w, r, web.Page{ - "URL": r.URL.Path, - "layout": "play", - "title": "Go Playground", - }) - }) -} - // newSite creates a new site for a given content and goroot file system pair // and registers it in mux to handle requests for host. // If host is the empty string, the registrations are for the wildcard host. @@ -479,6 +458,9 @@ func hostPathHandler(h http.Handler) http.Handler { r.URL.Scheme = "https" r.URL.Host = elem r.URL.Path = "/" + rest + + log.Print(r.URL.String()) + lw := &linkRewriter{ResponseWriter: w, host: r.Host} h.ServeHTTP(lw, r) lw.Flush() |
