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) }) }