av/cmd/audio-player/server.go

33 lines
677 B
Go
Raw Normal View History

package main
import (
"flag"
"log"
"net/http"
"strings"
)
var (
listen = flag.String("listen", ":8080", "listen address")
dir = flag.String("dir", ".", "directory to serve")
)
func main() {
flag.Parse()
log.Printf("listening on %q...", *listen)
h := wasmContentTypeSetter(http.FileServer(http.Dir(*dir)))
err := http.ListenAndServe(*listen, h)
if err != http.ErrServerClosed {
log.Fatal(err)
}
}
func wasmContentTypeSetter(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if strings.HasSuffix(r.URL.Path, ".wasm") {
w.Header().Set("content-type", "application/wasm")
}
h.ServeHTTP(w, r)
})
}