| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 // Package frontend implements HTTP server that handles requests to default | 5 // Package frontend implements HTTP server that handles requests to default |
| 6 // module. | 6 // module. |
| 7 package frontend | 7 package frontend |
| 8 | 8 |
| 9 import ( | 9 import ( |
| 10 "net/http" | 10 "net/http" |
| 11 "strings" | 11 "strings" |
| 12 | 12 |
| 13 "github.com/julienschmidt/httprouter" | 13 "github.com/julienschmidt/httprouter" |
| 14 "golang.org/x/net/context" | 14 "golang.org/x/net/context" |
| 15 "google.golang.org/appengine" | 15 "google.golang.org/appengine" |
| 16 | 16 |
| 17 "github.com/luci/gae/service/info" | 17 "github.com/luci/gae/service/info" |
| 18 "github.com/luci/luci-go/appengine/cmd/helloworld/proto" | 18 "github.com/luci/luci-go/appengine/cmd/helloworld/proto" |
| 19 "github.com/luci/luci-go/appengine/gaeauth/server" | 19 "github.com/luci/luci-go/appengine/gaeauth/server" |
| 20 "github.com/luci/luci-go/appengine/gaemiddleware" | 20 "github.com/luci/luci-go/appengine/gaemiddleware" |
| 21 "github.com/luci/luci-go/server/auth" | 21 "github.com/luci/luci-go/server/auth" |
| 22 "github.com/luci/luci-go/server/discovery" |
| 22 "github.com/luci/luci-go/server/middleware" | 23 "github.com/luci/luci-go/server/middleware" |
| 23 "github.com/luci/luci-go/server/prpc" | 24 "github.com/luci/luci-go/server/prpc" |
| 24 "github.com/luci/luci-go/server/templates" | 25 "github.com/luci/luci-go/server/templates" |
| 25 ) | 26 ) |
| 26 | 27 |
| 27 // templateBundle is used to render HTML templates. It provides a base args | 28 // templateBundle is used to render HTML templates. It provides a base args |
| 28 // passed to all templates. | 29 // passed to all templates. |
| 29 var templateBundle = &templates.Bundle{ | 30 var templateBundle = &templates.Bundle{ |
| 30 Loader: templates.FileSystemLoader("templates"), | 31 Loader: templates.FileSystemLoader("templates"), |
| 31 DebugMode: appengine.IsDevAppServer(), | 32 DebugMode: appengine.IsDevAppServer(), |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 | 71 |
| 71 //// Routes. | 72 //// Routes. |
| 72 | 73 |
| 73 func init() { | 74 func init() { |
| 74 router := httprouter.New() | 75 router := httprouter.New() |
| 75 server.InstallHandlers(router, base) | 76 server.InstallHandlers(router, base) |
| 76 router.GET("/", base(auth.Authenticate(indexPage))) | 77 router.GET("/", base(auth.Authenticate(indexPage))) |
| 77 | 78 |
| 78 var api prpc.Server | 79 var api prpc.Server |
| 79 helloworld.RegisterGreeterServer(&api, &greeterService{}) | 80 helloworld.RegisterGreeterServer(&api, &greeterService{}) |
| 81 discovery.Enable(&api) |
| 80 api.InstallHandlers(router, base) | 82 api.InstallHandlers(router, base) |
| 81 | 83 |
| 82 http.DefaultServeMux.Handle("/", router) | 84 http.DefaultServeMux.Handle("/", router) |
| 83 } | 85 } |
| 84 | 86 |
| 85 //// Handlers. | 87 //// Handlers. |
| 86 | 88 |
| 87 func indexPage(c context.Context, w http.ResponseWriter, r *http.Request, p http
router.Params) { | 89 func indexPage(c context.Context, w http.ResponseWriter, r *http.Request, p http
router.Params) { |
| 88 templates.MustRender(c, w, "pages/index.html", nil) | 90 templates.MustRender(c, w, "pages/index.html", nil) |
| 89 } | 91 } |
| OLD | NEW |