~yerinalexey/gobin

281860b2b75a6fff86043a8adb26055371d8f7ce — Alexey Yerin 11 months ago 85aab80
fix: not found on static files
1 files changed, 5 insertions(+), 4 deletions(-)

M main.go
M main.go => main.go +5 -4
@@ 108,15 108,16 @@ func main() {
		tmpl.ExecuteTemplate(w, "paste", Paste{id, contents})
	})

	// Static files
	fs := http.FileServer(http.Dir("static/"))
	r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", fs))

	/// Not found page
	r.PathPrefix("/").HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
			w.WriteHeader(404)
			tmpl.ExecuteTemplate(w, "not-found", nil)
	})

	// Static files
	fs := http.FileServer(http.Dir("static/"))
	r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", fs))

	log.Printf("Staring on port %s\n", port)
	log.Fatalln(http.ListenAndServe(":"+port, r))
}