Put all your static files in /static directory. If you put index.html into /static, it will be served up as welcome file.
Last active
April 27, 2018 20:34
-
-
Save treeder/8115c12dbc147a06b290 to your computer and use it in GitHub Desktop.
Serving static site on app engine with golang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
application: helloworld | |
version: 1 | |
runtime: go | |
api_version: go1 | |
handlers: | |
- url: /.* | |
script: _go_app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package hello | |
import ( | |
"fmt" | |
"net/http" | |
) | |
func init() { | |
http.HandleFunc("/ping", ping) | |
http.HandleFunc("/", handler) | |
} | |
func handler(w http.ResponseWriter, r *http.Request) { | |
http.ServeFile(w, r, "static/"+r.URL.Path) | |
} | |
func ping(w http.ResponseWriter, r *http.Request) { | |
fmt.Fprint(w, "pong") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using this approach will not use CDN and the benefits associated with it - faster response, less traffic on your instances