gddo-server: enable redirects talks.godoc.org and www.godoc.org

With the move away from nginx, all redirects need to be reimplmented
in gddo-server. This implements the redirect to send talks.godoc.org
to the go-talks App Engine project and www.godoc.org to godoc.org. In
nginx these were 301 redirects. I am making them 302 redirects now
because in the future these redirects are likely to change.

go-talks is just a standard App Engine app. There is no reason we
cannot run go-talks directly from the the talks.godoc.org domain and
likely will in the future.

Change-Id: I4b3e8dda74d31daeba8bd961932f774c6ff1442f
Reviewed-on: https://go-review.googlesource.com/21588
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Stephen Weinberg 2016-04-07 13:39:18 -04:00
Родитель aa04edd02b
Коммит 4b6647e4ec
1 изменённых файлов: 19 добавлений и 1 удалений

Просмотреть файл

@ -789,6 +789,19 @@ func (m rootHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
h.ServeHTTP(resp, req)
}
// otherDomainHandler redirects to another domain keeping the rest of the URL.
type otherDomainHandler struct {
scheme string
targetDomain string
}
func (h otherDomainHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
u := *req.URL
u.Scheme = h.scheme
u.Host = h.targetDomain
http.Redirect(w, req, u.String(), http.StatusFound)
}
func defaultBase(path string) string {
p, err := build.Default.Import(path, "", build.FindOnly)
if err != nil {
@ -950,7 +963,12 @@ func main() {
cacheBusters.Handler = mux
var root http.Handler = rootHandler{{"api.", apiMux}, {"", mux}}
var root http.Handler = rootHandler{
{"api.", apiMux},
{"talks.godoc.org", otherDomainHandler{"https", "go-talks.appspot.com"}},
{"www.godoc.org", otherDomainHandler{"https", "godoc.org"}},
{"", mux},
}
if gceLogName != "" {
logc, err := logging.NewClient(ctx, projID, gceLogName)
if err != nil {