-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaudiomass-server.go
executable file
·49 lines (40 loc) · 1.21 KB
/
audiomass-server.go
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"net/http"
_ "net/url"
"fmt"
"os/exec"
"strings"
"time"
)
func main() {
changeHeaderThenServe := func(h http.Handler) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Access-Control-Allow-Origin", "*")
if strings.Contains(r.URL.Path, ".wasm") {
w.Header().Add("Content-Type", "application/wasm")
}
if strings.Contains(r.URL.Path, ".js") {
var epoch = time.Unix(0, 0).Format(time.RFC1123)
var noCacheHeaders = map[string]string{
"Expires": epoch,
"Cache-Control": "no-cache, private, max-age=0",
"Pragma": "no-cache",
"X-Accel-Expires": "0",
}
for k, v := range noCacheHeaders {
w.Header().Set(k, v)
}
}
fmt.Println("Req:", r.Host, r.URL.Path)
h.ServeHTTP(w, r)
}
}
go func() {
cmd := exec.Command("open", "-a", "Google Chrome", "http://localhost:5055/")
cmd.Output()
}()
fmt.Printf("\nListening on http://localhost:5055 \n\n")
http.Handle("/", changeHeaderThenServe(http.FileServer(http.Dir("."))))
panic(http.ListenAndServe(":5055", nil))
}