diff options
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 32 |
1 files changed, 32 insertions, 0 deletions
@@ -0,0 +1,32 @@ +package main + +import ( + "flag" + "fmt" + "log" + "net/http" + "os" +) + +func accessLog(h http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + log.Println(r.Method, r.URL.Path, r.RemoteAddr) + h.ServeHTTP(w, r) + }) +} + +func main() { + ip_f := flag.String("ip", "0.0.0.0", "IP adress to listen on.") + port_f := flag.String("port", "3000", "Port to listen on.") + dir_f := flag.String("dir", ".", "Directory to serve.") + + flag.Parse() + + port := os.Getenv("PORT") + if port == "" { + port = *port_f + } + + fmt.Println("Starting uhttpd serving \"" + *dir_f + "\" on " + *ip_f + ":" + port + ".") + log.Fatal(http.ListenAndServe(*ip_f+":"+port, accessLog(http.FileServer(http.Dir(*dir_f))))) +} |
