/ web.go
web.go
 1  //go:generate browserify web/index.js web/js/ws.js -o static/bundle.js
 2  //go:generate cp web/node_modules/three/build/three.min.js static/three.min.js
 3  //go:generate cp web/js/controls/TrackballControls.js static/
 4  //go:generate cp web/js/controls/FlyControls.js static/
 5  //go:generate go-bindata-assetfs static/...
 6  package main
 7  
 8  import (
 9  	"log"
10  	"net/http"
11  )
12  
13  func startWeb(ws *WSServer, bind string) {
14  	fs := http.FileServer(assetFS())
15  	http.Handle("/", noCacheMiddleware(fs))
16  	http.HandleFunc("/ws", ws.Handle)
17  	log.Fatal(http.ListenAndServe(bind, nil))
18  }
19  
20  func noCacheMiddleware(h http.Handler) http.Handler {
21  	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
22  		w.Header().Add("Cache-Control", "max-age=0, no-cache")
23  		h.ServeHTTP(w, r)
24  	})
25  }