aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristine Dodrill <me@christine.website>2017-03-29 09:52:27 -0700
committerChristine Dodrill <me@christine.website>2017-03-29 09:52:27 -0700
commit1b92034f41a4b71d3d9fd0fe3b01f4532985a3b4 (patch)
treebb224cc0f5215f2ecbca5ffecb12bedba2ffe781
parent60226001102de6ca0475cb9852a99f9e1b722937 (diff)
downloadxesite-1b92034f41a4b71d3d9fd0fe3b01f4532985a3b4.tar.xz
xesite-1b92034f41a4b71d3d9fd0fe3b01f4532985a3b4.zip
backend: use a discrete ServeMux
-rw-r--r--backend/christine.website/main.go26
1 files changed, 14 insertions, 12 deletions
diff --git a/backend/christine.website/main.go b/backend/christine.website/main.go
index fa3e0ab..35bbbc5 100644
--- a/backend/christine.website/main.go
+++ b/backend/christine.website/main.go
@@ -102,9 +102,11 @@ func init() {
}
func main() {
- http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {})
- http.HandleFunc("/api/blog/posts", writeBlogPosts)
- http.HandleFunc("/api/blog/post", func(w http.ResponseWriter, r *http.Request) {
+ mux := http.NewServeMux()
+
+ mux.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {})
+ mux.HandleFunc("/api/blog/posts", writeBlogPosts)
+ mux.HandleFunc("/api/blog/post", func(w http.ResponseWriter, r *http.Request) {
q := r.URL.Query()
name := q.Get("name")
@@ -122,7 +124,7 @@ func main() {
fail:
http.Error(w, "Not Found", http.StatusNotFound)
})
- http.HandleFunc("/api/resume", func(w http.ResponseWriter, r *http.Request) {
+ mux.HandleFunc("/api/resume", func(w http.ResponseWriter, r *http.Request) {
json.NewEncoder(w).Encode(struct {
Body string `json:"body"`
}{
@@ -141,28 +143,28 @@ func main() {
log.Fatal("frontend: ", err)
}
- http.Handle("/dist/", http.FileServer(fe))
+ mux.Handle("/dist/", http.FileServer(fe))
} else {
log.Println("serving site frontend from filesystem")
- http.Handle("/dist/", http.FileServer(http.Dir("./frontend/static/")))
+ mux.Handle("/dist/", http.FileServer(http.Dir("./frontend/static/")))
}
- http.Handle("/static/", http.FileServer(http.Dir(".")))
- http.HandleFunc("/", writeIndexHTML)
+ mux.Handle("/static/", http.FileServer(http.Dir(".")))
+ mux.HandleFunc("/", writeIndexHTML)
port := os.Getenv("PORT")
if port == "" {
port = "9090"
}
- http.HandleFunc("/blog.rss", createFeed)
- http.HandleFunc("/blog.atom", createAtom)
- http.HandleFunc("/keybase.txt", func(w http.ResponseWriter, r *http.Request) {
+ mux.HandleFunc("/blog.rss", createFeed)
+ mux.HandleFunc("/blog.atom", createAtom)
+ mux.HandleFunc("/keybase.txt", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "./static/keybase.txt")
})
n := negroni.Classic()
- n.UseHandler(http.DefaultServeMux)
+ n.UseHandler(mux)
log.Fatal(http.ListenAndServe(":"+port, n))
}