OLD | NEW |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /* | 5 /* |
6 Serves a webpage for easy management of Skia bugs. | 6 Serves a webpage for easy management of Skia bugs. |
7 | 7 |
8 WARNING: This server is NOT secure and should not be made publicly | 8 WARNING: This server is NOT secure and should not be made publicly |
9 accessible. | 9 accessible. |
10 */ | 10 */ |
(...skipping 17 matching lines...) Expand all Loading... |
28 ) | 28 ) |
29 | 29 |
30 import "github.com/gorilla/securecookie" | 30 import "github.com/gorilla/securecookie" |
31 | 31 |
32 const ( | 32 const ( |
33 certFile = "certs/cert.pem" | 33 certFile = "certs/cert.pem" |
34 keyFile = "certs/key.pem" | 34 keyFile = "certs/key.pem" |
35 issueComment = "Edited by BugChomper" | 35 issueComment = "Edited by BugChomper" |
36 oauthCallbackPath = "/oauth2callback" | 36 oauthCallbackPath = "/oauth2callback" |
37 oauthConfigFile = "oauth_client_secret.json" | 37 oauthConfigFile = "oauth_client_secret.json" |
38 defaultPort = 8000 | |
39 localHost = "127.0.0.1" | 38 localHost = "127.0.0.1" |
40 maxSessionLen = time.Duration(3600 * time.Second) | 39 maxSessionLen = time.Duration(3600 * time.Second) |
41 priorityPrefix = "Priority-" | 40 priorityPrefix = "Priority-" |
42 project = "skia" | 41 project = "skia" |
43 cookieName = "BugChomperCookie" | 42 cookieName = "BugChomperCookie" |
44 ) | 43 ) |
45 | 44 |
| 45 // Flags: |
| 46 var ( |
| 47 port = flag.String("port", ":8000", "HTTP service address (e.g., ':8000'
)") |
| 48 ) |
| 49 |
46 var ( | 50 var ( |
47 scheme = "http" | 51 scheme = "http" |
48 | 52 |
49 curdir, _ = filepath.Abs(".") | 53 curdir, _ = filepath.Abs(".") |
50 templatePath, _ = filepath.Abs("templates") | 54 templatePath, _ = filepath.Abs("templates") |
51 templates = template.Must(template.ParseFiles( | 55 templates = template.Must(template.ParseFiles( |
52 path.Join(templatePath, "bug_chomper.html"), | 56 path.Join(templatePath, "bug_chomper.html"), |
53 path.Join(templatePath, "submitted.html"), | 57 path.Join(templatePath, "submitted.html"), |
54 path.Join(templatePath, "error.html"))) | 58 path.Join(templatePath, "error.html"))) |
55 | 59 |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 // Run the BugChomper server. | 359 // Run the BugChomper server. |
356 func main() { | 360 func main() { |
357 var public bool | 361 var public bool |
358 flag.BoolVar( | 362 flag.BoolVar( |
359 &public, "public", false, "Make this server publicly accessible.
") | 363 &public, "public", false, "Make this server publicly accessible.
") |
360 flag.Parse() | 364 flag.Parse() |
361 | 365 |
362 http.HandleFunc("/", handleRoot) | 366 http.HandleFunc("/", handleRoot) |
363 http.HandleFunc(oauthCallbackPath, handleOAuth2Callback) | 367 http.HandleFunc(oauthCallbackPath, handleOAuth2Callback) |
364 http.Handle("/res/", http.FileServer(http.Dir(curdir))) | 368 http.Handle("/res/", http.FileServer(http.Dir(curdir))) |
365 » port := ":" + strconv.Itoa(defaultPort) | 369 » log.Println("Server is running at " + scheme + "://" + localHost + *port
) |
366 » log.Println("Server is running at " + scheme + "://" + localHost + port) | |
367 var err error | 370 var err error |
368 if public { | 371 if public { |
369 log.Println("WARNING: This server is not secure and should not b
e made " + | 372 log.Println("WARNING: This server is not secure and should not b
e made " + |
370 "publicly accessible.") | 373 "publicly accessible.") |
371 scheme = "https" | 374 scheme = "https" |
372 » » err = http.ListenAndServeTLS(port, certFile, keyFile, nil) | 375 » » err = http.ListenAndServeTLS(*port, certFile, keyFile, nil) |
373 } else { | 376 } else { |
374 scheme = "http" | 377 scheme = "http" |
375 » » err = http.ListenAndServe(localHost+port, nil) | 378 » » err = http.ListenAndServe(localHost+*port, nil) |
376 } | 379 } |
377 if err != nil { | 380 if err != nil { |
378 log.Println(err.Error()) | 381 log.Println(err.Error()) |
379 } | 382 } |
380 } | 383 } |
OLD | NEW |