From 0ed0106aa4f2b146353275e24de75cdef4fb9f6c Mon Sep 17 00:00:00 2001 From: Mark Mentovai Date: Wed, 21 Oct 2015 09:42:29 -0400 Subject: [PATCH] Add /bug redirects to the home page AppEngine app MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit /bug/ redirects to the Crashpad project on Monorail. /bug/new redirects to the “new issue” screen, and /bug/123 redirects to the named bug. R=andybons@chromium.org Review URL: https://codereview.chromium.org/1415063002 . --- doc/appengine/main.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/doc/appengine/main.go b/doc/appengine/main.go index 261440d4..e05870f5 100644 --- a/doc/appengine/main.go +++ b/doc/appengine/main.go @@ -31,13 +31,16 @@ import ( "google.golang.org/appengine/urlfetch" ) -const baseURL = "https://chromium.googlesource.com/crashpad/crashpad/+/doc/doc/generated/?format=TEXT" - func init() { http.HandleFunc("/", handler) } func handler(w http.ResponseWriter, r *http.Request) { + const ( + baseURL = "https://chromium.googlesource.com/crashpad/crashpad/+/doc/doc/generated/?format=TEXT" + bugBaseURL = "https://bugs.chromium.org/p/crashpad/" + ) + ctx := appengine.NewContext(r) client := urlfetch.Client(ctx) @@ -47,6 +50,17 @@ func handler(w http.ResponseWriter, r *http.Request) { return } + if r.URL.Path == "/bug" || r.URL.Path == "/bug/" { + http.Redirect(w, r, bugBaseURL, http.StatusFound) + return + } else if r.URL.Path == "/bug/new" { + http.Redirect(w, r, bugBaseURL+"issues/entry", http.StatusFound) + return + } else if strings.HasPrefix(r.URL.Path, "/bug/") { + http.Redirect(w, r, bugBaseURL+"issues/detail?id="+r.URL.Path[5:], http.StatusFound) + return + } + u, err := url.Parse(baseURL) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError)