OLD | NEW |
| (Empty) |
1 // Copyright 2017 The LUCI Authors. All rights reserved. | |
2 // Use of this source code is governed under the Apache License, Version 2.0 | |
3 // that can be found in the LICENSE file. | |
4 | |
5 package main | |
6 | |
7 import ( | |
8 "fmt" | |
9 "log" | |
10 "net/http" | |
11 "strings" | |
12 | |
13 "github.com/luci/luci-go/milo/appengine/common" | |
14 "github.com/luci/luci-go/server/auth" | |
15 "github.com/luci/luci-go/server/router" | |
16 ) | |
17 | |
18 // Where it all begins!!! | |
19 func main() { | |
20 r := router.New() | |
21 | |
22 base := common.FlexBase() | |
23 r.GET("/log/raw/*path", base, rawLog) | |
24 | |
25 // Health check, for the appengine flex environment. | |
26 http.HandleFunc("/_ah/health", healthCheckHandler) | |
27 // And everything else. | |
28 http.Handle("/", r) | |
29 | |
30 log.Print("Listening on port 8080") | |
31 log.Fatal(http.ListenAndServe(":8080", nil)) | |
32 } | |
33 | |
34 func page(c *router.Context, status int, msg string) { | |
35 c.Writer.WriteHeader(status) | |
36 fmt.Fprintf(c.Writer, msg) | |
37 } | |
38 | |
39 func errorPage(c *router.Context, msg string) { | |
40 page(c, http.StatusInternalServerError, msg) | |
41 } | |
42 | |
43 func rawLog(c *router.Context) { | |
44 path := c.Params.ByName("path") | |
45 if path == "" { | |
46 page(c, http.StatusBadRequest, "missing path") | |
47 return | |
48 } | |
49 path = strings.TrimLeft(path, "/") | |
50 host := c.Request.FormValue("host") | |
51 if host == "" { | |
52 host = "luci-logdog.appspot.com" | |
53 } | |
54 err := logHandler(c.Context, c.Writer, host, path) | |
55 switch err { | |
56 case nil: | |
57 // Everything is fine | |
58 case errNoAuth: | |
59 // Redirect to login page | |
60 loginURL, err := auth.LoginURL(c.Context, c.Request.URL.Path) | |
61 if err != nil { | |
62 fmt.Fprintf(c.Writer, "Encountered error generating logi
n url: %s\n", err.Error()) | |
63 return | |
64 } | |
65 http.Redirect(c.Writer, c.Request, loginURL, http.StatusTemporar
yRedirect) | |
66 return | |
67 default: | |
68 fmt.Fprintf(c.Writer, "Encountered error: %s", err.Error()) | |
69 } | |
70 } | |
71 | |
72 func healthCheckHandler(w http.ResponseWriter, r *http.Request) { | |
73 fmt.Fprint(w, "ok") | |
74 } | |
OLD | NEW |