diff --git a/snippetbox/cmd/web/main.go b/snippetbox/cmd/web/main.go index 0c4da5d..b0b88e2 100644 --- a/snippetbox/cmd/web/main.go +++ b/snippetbox/cmd/web/main.go @@ -1,18 +1,28 @@ package main import ( + "flag" "log" "net/http" ) // main it's the snippetbox webapp func main() { + //configuration + addr := flag.String("addr", ":4000", "HTTP network address") + flag.Parse() + mux := http.NewServeMux() + + // setup server for static files + fileServer := http.FileServer(http.Dir("./ui/static")) + mux.Handle("/static/", http.StripPrefix("/static", fileServer)) + mux.HandleFunc("/", home) mux.HandleFunc("/snippet/view", snippetView) mux.HandleFunc("/snippet/create", snippetCreate) - log.Print("starting a server on :4000") - err := http.ListenAndServe(":4000", mux) + log.Printf("starting a server on %s", *addr) + err := http.ListenAndServe(*addr, mux) log.Fatal(err) } diff --git a/snippetbox/ui/html/base.tmpl b/snippetbox/ui/html/base.tmpl index 3277315..3786d63 100644 --- a/snippetbox/ui/html/base.tmpl +++ b/snippetbox/ui/html/base.tmpl @@ -4,6 +4,9 @@