aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2021-05-26 15:34:00 -0400
committerRuss Cox <rsc@golang.org>2021-05-26 20:33:42 +0000
commitd84d70769154a47449deb0ec3c003301d1d21958 (patch)
tree6d6fee4eba68729d7813c1c593003091b72ddf8c
parent6c0cee0cf27305ffc682223e33867aa5b5a86744 (diff)
downloadgo-x-website-d84d70769154a47449deb0ec3c003301d1d21958.tar.xz
go.dev/cmd/frontend: fix learn.go.dev by redirecting to go.dev/learn
The old Hugo setup was strange in that Hugo thought it was generating pages for go.dev/learn, and then we put in a redirect from go.dev/learn to learn.go.dev, and then we had a whole separate app just for serving files in that subtree. All the actual file serving was done in app.yaml using static file directives, not anything in Go. In the migration to a Go web server, I did not make learn.go.dev/ work, so it was showing the main go.dev page instead, which is clearly bad. I spent a little while trying to make the Go server behave like the old setup, but in the end I gave up and removed all the subterfuge. Now the pages are served from go.dev/learn, same as in the _content tree, and there is a redirect from learn.go.dev/anything to go.dev/learn/anything. Given how much trouble I had getting the server to work the other way, it seemed like we'd keep tripping over this special case as we make more changes. And given that the long-term plan is to move everything onto go.dev, it seemed better all around to just start telling the truth now. This fix is already deployed, to fix the broken learn.go.dev. Change-Id: I774850ade327623eefffc785f923f5002f3abff8 Reviewed-on: https://go-review.googlesource.com/c/website/+/322970 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Jamal Carvalho <jamal@golang.org>
-rw-r--r--go.dev/cmd/frontend/main.go7
1 files changed, 6 insertions, 1 deletions
diff --git a/go.dev/cmd/frontend/main.go b/go.dev/cmd/frontend/main.go
index 93572e43..3d9e0a40 100644
--- a/go.dev/cmd/frontend/main.go
+++ b/go.dev/cmd/frontend/main.go
@@ -10,6 +10,7 @@ import (
"net/http"
"net/url"
"os"
+ "strings"
"golang.org/x/go.dev/cmd/internal/site"
)
@@ -32,7 +33,7 @@ func main() {
}
http.Handle("/", addCSP(http.FileServer(godev)))
http.Handle("/explore/", http.StripPrefix("/explore/", redirectHosts(discoveryHosts)))
- http.Handle("/learn/", http.StripPrefix("/learn/", redirectHosts(map[string]string{"": "learn.go.dev"})))
+ http.Handle("learn.go.dev/", http.HandlerFunc(redirectLearn))
addr := ":" + listenPort()
if addr == ":0" {
@@ -47,6 +48,10 @@ func main() {
log.Print(http.Serve(l, nil))
}
+func redirectLearn(w http.ResponseWriter, r *http.Request) {
+ http.Redirect(w, r, "https://go.dev/learn/"+strings.TrimPrefix(r.URL.Path, "/"), http.StatusMovedPermanently)
+}
+
func listenPort() string {
if p := os.Getenv("PORT"); p != "" {
return p