| 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 "regexp" |
| 12 "strings" |
| 13 |
| 14 "github.com/luci/luci-go/milo/appengine/common" |
| 15 "github.com/luci/luci-go/server/auth" |
| 16 "github.com/luci/luci-go/server/router" |
| 17 ) |
| 18 |
| 19 // Where it all begins!!! |
| 20 func main() { |
| 21 r := router.New() |
| 22 |
| 23 base := common.FlexBase() |
| 24 r.GET("/log/raw/*path", base, rawLog) |
| 25 |
| 26 // Health check, for the appengine flex environment. |
| 27 http.HandleFunc("/_ah/health", healthCheckHandler) |
| 28 // And everything else. |
| 29 http.Handle("/", r) |
| 30 |
| 31 log.Print("Listening on port 8080") |
| 32 log.Fatal(http.ListenAndServe(":8080", nil)) |
| 33 } |
| 34 |
| 35 func errorPage(c *router.Context, msg string) { |
| 36 c.Writer.WriteHeader(http.StatusInternalServerError) |
| 37 fmt.Fprintf(c.Writer, msg) |
| 38 } |
| 39 |
| 40 func rawLog(c *router.Context) { |
| 41 path := c.Params.ByName("path") |
| 42 if path == "" { |
| 43 errorPage(c, "missing path") |
| 44 return |
| 45 } |
| 46 path = strings.TrimLeft(path, "/") |
| 47 host := c.Request.FormValue("host") |
| 48 if host == "" { |
| 49 host = "luci-logdog.appspot.com" |
| 50 } |
| 51 err := logHandler(c.Context, c.Writer, host, path) |
| 52 switch err { |
| 53 case nil: |
| 54 // Everything is fine |
| 55 case errNoAuth: |
| 56 // Redirect to login page |
| 57 loginURL, err := auth.LoginURL(c.Context, c.Request.URL.Path) |
| 58 if err != nil { |
| 59 fmt.Fprintf(c.Writer, "Encountered error generating logi
n url: %s\n", err.Error()) |
| 60 return |
| 61 } |
| 62 http.Redirect(c.Writer, c.Request, loginURL, http.StatusTemporar
yRedirect) |
| 63 return |
| 64 default: |
| 65 fmt.Fprintf(c.Writer, "Encountered error: %s", err.Error()) |
| 66 } |
| 67 } |
| 68 |
| 69 var rRaw = regexp.MustCompile(`/log/raw/(.*)`) |
| 70 |
| 71 func healthCheckHandler(w http.ResponseWriter, r *http.Request) { |
| 72 fmt.Fprint(w, "ok") |
| 73 } |
| OLD | NEW |