github.com/aykevl/tinygo@v0.5.0/src/examples/wasm/server.go (about)

     1  package main
     2  
     3  import (
     4  	"log"
     5  	"net/http"
     6  	"strings"
     7  )
     8  
     9  const dir = "./html"
    10  
    11  func main() {
    12  	fs := http.FileServer(http.Dir(dir))
    13  	log.Print("Serving " + dir + " on http://localhost:8080")
    14  	http.ListenAndServe(":8080", http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
    15  		if strings.HasSuffix(req.URL.Path, ".wasm") {
    16  			resp.Header().Set("content-type", "application/wasm")
    17  		}
    18  
    19  		fs.ServeHTTP(resp, req)
    20  	}))
    21  }