diff options
-rw-r--r-- | .gcloudignore | 2 | ||||
-rw-r--r-- | app.yaml | 14 | ||||
-rw-r--r-- | appengine.go | 13 | ||||
-rw-r--r-- | blog.go | 9 | ||||
-rw-r--r-- | local.go | 11 |
5 files changed, 34 insertions, 15 deletions
diff --git a/.gcloudignore b/.gcloudignore new file mode 100644 index 0000000..0030d4f --- /dev/null +++ b/.gcloudignore @@ -0,0 +1,2 @@ +.gcloudignore +.git @@ -1,7 +1,13 @@ service: blog -runtime: go -api_version: go1.9 +runtime: go111 +env_variables: + GOLANGORG_CHECK_COUNTRY: true + +default_expiration: "7d" + +# Keep these static file handlers in sync with blog.go. +# They're here for improved latency across global regions. handlers: - url: /favicon.ico static_files: static/favicon.ico @@ -15,8 +21,4 @@ handlers: static_dir: static/fonts http_headers: Content-Type: application/font-woff -- url: /.* - script: _go_app secure: always - -nobuild_files: ^(support|content)/ diff --git a/appengine.go b/appengine.go index 288247e..3b65bc7 100644 --- a/appengine.go +++ b/appengine.go @@ -2,27 +2,32 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build appengine - // This file implements an App Engine blog server. package main import ( + "log" "net/http" + "os" "golang.org/x/tools/blog" ) -func init() { +func gaeMain() { config.ContentPath = "content/" config.TemplatePath = "template/" s, err := blog.NewServer(config) if err != nil { - panic(err) + log.Fatalln(err) } http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Strict-Transport-Security", "max-age=31536000; preload") s.ServeHTTP(w, r) }) + port := os.Getenv("PORT") + if port == "" { + port = "8080" + } + log.Fatal(http.ListenAndServe(":"+port, nil)) } @@ -37,8 +37,13 @@ func init() { } http.HandleFunc("/blog", redirect) http.HandleFunc("/blog/", redirect) - http.Handle("/fonts/", http.FileServer(http.Dir("static"))) - http.Handle("/fonts.css", http.FileServer(http.Dir("static"))) + + // Keep these static file handlers in sync with app.yaml. + static := http.FileServer(http.Dir("static")) + http.Handle("/favicon.ico", static) + http.Handle("/fonts.css", static) + http.Handle("/fonts/", static) + http.Handle("/lib/godoc/", http.StripPrefix("/lib/godoc/", http.HandlerFunc(staticHandler))) } @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build !appengine - // This file implements a stand-alone blog server. package main @@ -81,6 +79,13 @@ func newServer(reload bool, staticPath string, config blog.Config) (http.Handler func main() { flag.Parse() + + if os.Getenv("GAE_ENV") == "standard" { + log.Println("running in App Engine Standard mode") + gaeMain() + return + } + config.ContentPath = *contentPath config.TemplatePath = *templatePath mux, err := newServer(*reload, *staticPath, config) @@ -100,7 +105,7 @@ func main() { func reloadingBlogServer(w http.ResponseWriter, r *http.Request) { s, err := blog.NewServer(config) if err != nil { - http.Error(w, err.Error(), 500) + http.Error(w, err.Error(), http.StatusInternalServerError) return } s.ServeHTTP(w, r) |