blob: cf428ed7509814fcfb6a7bba6592d36bb24e18fd (
plain)
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
26
27
28
29
30
31
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)))))
}
|