-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
46 lines (40 loc) · 1.16 KB
/
main.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
package main
import (
"context"
"embed"
"log"
"net/http"
"os"
"github.com/soypat/sdf3ui/model"
)
//go:generate go run ./assets/gen_assets.go
var (
notifyRenderer = newRendererHandler()
// Embed assets into binary.
//go:embed assets/*
assetsFS embed.FS
)
func main() {
if len(os.Args) != 2 {
log.Fatal("first and only argument must be file name of program")
}
filename := os.Args[1]
if _, err := os.Stat(filename); err != nil {
log.Fatal(err)
}
notifyRenderer.SetFileTarget(filename)
err := notifyRenderer.renderFile(context.Background(), filename)
if err != nil {
log.Fatal(err)
}
go notifyRenderer.Start(context.Background())
// Register http server for serving WASM and other resources.
wsm, err := WASMHandler()
http.Handle("/", wsm)
http.Handle("/"+model.WSSubprotocol, ¬ifyRenderer.server)
http.HandleFunc(model.SaveSTLEndpoint, notifyRenderer.server.createSTLHandler)
http.Handle("/assets/", http.FileServer(http.FS(assetsFS)))
http.HandleFunc(model.ShapeEndpoint, notifyRenderer.server.serveShapeHTTP)
log.Printf("listening on %v", model.HTTPBaseURL)
log.Fatal(http.ListenAndServe(model.HTTPAddr, newBaseMiddleware(http.DefaultServeMux)))
}