mirror of https://github.com/perkeep/perkeep.git
website: simplify docHandler
don't strip the "/doc" prefix, which simplifies some of the file handling logic. Also add a test case for the /docs/ => /doc/ redirect. Change-Id: I96c60bc031daaeff7f78ca854b60bdc542913b3d
This commit is contained in:
parent
a7a63cfd0d
commit
1f0340b436
|
@ -250,7 +250,7 @@ func mainHandler(rw http.ResponseWriter, req *http.Request) {
|
|||
}
|
||||
|
||||
func docHandler(rw http.ResponseWriter, req *http.Request) {
|
||||
findAndServeFile(rw, req, filepath.Join(filepath.Dir(*root), "doc"))
|
||||
findAndServeFile(rw, req, filepath.Dir(*root))
|
||||
}
|
||||
|
||||
// modtime is the modification time of the resource to be served, or IsZero().
|
||||
|
@ -307,7 +307,7 @@ func findAndServeFile(rw http.ResponseWriter, req *http.Request, root string) {
|
|||
// the URL with a trailing slash so relative links within that
|
||||
// directory work.
|
||||
if fi.IsDir() && !strings.HasSuffix(req.URL.Path, "/") {
|
||||
http.Redirect(rw, req, "/doc"+req.URL.Path+"/", http.StatusFound)
|
||||
http.Redirect(rw, req, req.URL.Path+"/", http.StatusFound)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -770,7 +770,7 @@ func main() {
|
|||
mux.Handle("/lists", redirTo("/community"))
|
||||
|
||||
mux.HandleFunc("/contributors", contribHandler())
|
||||
mux.Handle("/doc/", http.StripPrefix("/doc", http.HandlerFunc(docHandler)))
|
||||
mux.HandleFunc("/doc/", docHandler)
|
||||
mux.HandleFunc("/", mainHandler)
|
||||
|
||||
if buildbotHost != "" && buildbotBackend != "" {
|
||||
|
|
|
@ -30,6 +30,7 @@ func TestRedirect(t *testing.T) {
|
|||
{"/gw/502aff1fd522c454e39a3723b596aca43d206d4e", "https://camlistore.googlesource.com/camlistore/+/502aff1fd522c454e39a3723b596aca43d206d4e"},
|
||||
{"/gw/doc", "https://camlistore.googlesource.com/camlistore/+/master/doc"},
|
||||
{"/code/?p=camlistore.git;a=commit;h=b0d2a8f0e5f27bbfc025a96ec3c7896b42d198ed", "https://camlistore.googlesource.com/camlistore/+/b0d2a8f0e5f27bbfc025a96ec3c7896b42d198ed"},
|
||||
{"/docs/schema/", "/doc/schema/"},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
u, err := url.ParseRequestURI(tt.in)
|
||||
|
|
Loading…
Reference in New Issue