Chromium Code Reviews| Index: tools/bug_chomper/src/server/server.go |
| diff --git a/tools/bug_chomper/src/server/server.go b/tools/bug_chomper/src/server/server.go |
| index 1388d00b9349be37e6032b36d36a2ce736d19d26..7fdae93c7bd17662d6831c32eed2a93087bcd816 100644 |
| --- a/tools/bug_chomper/src/server/server.go |
| +++ b/tools/bug_chomper/src/server/server.go |
| @@ -20,8 +20,9 @@ import ( |
| "log" |
| "net/http" |
| "net/url" |
| - "path" |
| + "os" |
| "path/filepath" |
| + "runtime" |
| "strconv" |
| "strings" |
| "time" |
| @@ -49,20 +50,31 @@ var ( |
| ) |
| var ( |
| - scheme = "http" |
| - |
| - curdir, _ = filepath.Abs(".") |
| - templatePath, _ = filepath.Abs("templates") |
| - templates = template.Must(template.ParseFiles( |
| - path.Join(templatePath, "bug_chomper.html"), |
| - path.Join(templatePath, "submitted.html"), |
| - path.Join(templatePath, "error.html"))) |
| + // templates is the list of html templates used by bug_chomper. |
| + templates *template.Template = nil |
| + scheme = "http" |
| hashKey = securecookie.GenerateRandomKey(32) |
| blockKey = securecookie.GenerateRandomKey(32) |
| secureCookie = securecookie.New(hashKey, blockKey) |
| ) |
| +func init() { |
| + // Change the current working directory to two directories up from this |
| + // source file so that we can read templates. |
| + _, filename, _, _ := runtime.Caller(0) |
| + cwd := filepath.Join(filepath.Dir(filename), "../..") |
| + if err := os.Chdir(cwd); err != nil { |
| + log.Fatal(err) |
| + } |
| + |
| + templates = template.Must(template.ParseFiles( |
| + filepath.Join(cwd, "templates/bug_chomper.html"), |
|
tfarina
2014/10/15 22:18:14
cwd results in the abs path where running ./run_se
|
| + filepath.Join(cwd, "templates/submitted.html"), |
| + filepath.Join(cwd, "templates/error.html"), |
| + )) |
| +} |
| + |
| // SessionState contains data for a given session. |
| type SessionState struct { |
| IssueTracker *issue_tracker.IssueTracker |
| @@ -363,7 +375,7 @@ func main() { |
| http.HandleFunc("/", handleRoot) |
| http.HandleFunc(oauthCallbackPath, handleOAuth2Callback) |
| - http.Handle("/res/", http.FileServer(http.Dir(curdir))) |
| + http.Handle("/res/", http.FileServer(http.Dir("./"))) |
| log.Println("Server is running at " + scheme + "://" + localHost + *port) |
| var err error |
| if *public { |