Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(394)

Side by Side Diff: doc/go/docserver/main.go

Issue 872873002: Return 404s for unknown URLs. Also scroll back to the top of the page upon following a link. (Closed) Base URL: https://skia.googlesource.com/buildbot@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | doc/templates/index.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // docserver is a super simple Markdown (CommonMark) server. 1 // docserver is a super simple Markdown (CommonMark) server.
2 // 2 //
3 // Every directory has an index.md and the first line of index.md is used as 3 // Every directory has an index.md and the first line of index.md is used as
4 // the display name for that directory. The directory name itself is used in 4 // the display name for that directory. The directory name itself is used in
5 // the URL path. See README.md for more design details. 5 // the URL path. See README.md for more design details.
6 package main 6 package main
7 7
8 import ( 8 import (
9 "flag" 9 "flag"
10 "fmt"
11 "mime" 10 "mime"
12 "net/http" 11 "net/http"
13 "path/filepath" 12 "path/filepath"
14 "runtime" 13 "runtime"
15 "text/template" 14 "text/template"
16 "time" 15 "time"
17 16
18 "strconv" 17 "strconv"
19 "strings" 18 "strings"
20 19
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 // When running in local mode reload all templates and rebuild the navig ation 105 // When running in local mode reload all templates and rebuild the navig ation
107 // menu on every request, so we don't have to start and stop the server while 106 // menu on every request, so we don't have to start and stop the server while
108 // developing. 107 // developing.
109 if *local { 108 if *local {
110 d.BuildNavigation() 109 d.BuildNavigation()
111 loadTemplates() 110 loadTemplates()
112 } 111 }
113 112
114 filename, raw, err := d.RawFilename(r.URL.Path) 113 filename, raw, err := d.RawFilename(r.URL.Path)
115 if err != nil { 114 if err != nil {
116 » » util.ReportError(w, r, err, fmt.Sprintf("Failed to find a matchi ng file for %q %q", r.URL.Path, filename)) 115 » » glog.Infof("Request for unknown path: %s", r.URL.Path)
116 » » http.NotFound(w, r)
117 return 117 return
118 } 118 }
119 119
120 // Set the content type. 120 // Set the content type.
121 mimetype := "text/html" 121 mimetype := "text/html"
122 if raw { 122 if raw {
123 mimetype = mime.TypeByExtension(filepath.Ext(filename)) 123 mimetype = mime.TypeByExtension(filepath.Ext(filename))
124 } 124 }
125 w.Header().Set("Content-Type", mimetype) 125 w.Header().Set("Content-Type", mimetype)
126 126
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 common.InitWithMetrics("docserver", graphiteServer) 160 common.InitWithMetrics("docserver", graphiteServer)
161 Init() 161 Init()
162 162
163 // Resources are served directly. 163 // Resources are served directly.
164 http.HandleFunc("/res/", autogzip.HandleFunc(makeResourceHandler())) 164 http.HandleFunc("/res/", autogzip.HandleFunc(makeResourceHandler()))
165 http.HandleFunc("/", autogzip.HandleFunc(mainHandler)) 165 http.HandleFunc("/", autogzip.HandleFunc(mainHandler))
166 166
167 glog.Infoln("Ready to serve.") 167 glog.Infoln("Ready to serve.")
168 glog.Fatal(http.ListenAndServe(*port, nil)) 168 glog.Fatal(http.ListenAndServe(*port, nil))
169 } 169 }
OLDNEW
« no previous file with comments | « no previous file | doc/templates/index.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698