commands/serve.go (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
package commands import ( "fmt" "log" "net/http" ) func requestLog(h http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { h.ServeHTTP(w, r) log.Printf("%s\t%s", r.Method, r.URL.Path) }) } func Serve(addr string) error { fs := http.FileServer(http.Dir("./build")) mux := http.NewServeMux() mux.Handle("/", fs) fmt.Printf("vite: serving on %s\n", addr) if err := http.ListenAndServe(addr, requestLog(mux)); err != nil { return err } return nil } |