|
|
@ -36,41 +36,36 @@ func (web *WebAddon) echo(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
|
|
|
|
|
|
type WebAddon struct {
|
|
|
|
type WebAddon struct {
|
|
|
|
addon.Base
|
|
|
|
addon.Base
|
|
|
|
addr string
|
|
|
|
upgrader *websocket.Upgrader
|
|
|
|
upgrader *websocket.Upgrader
|
|
|
|
|
|
|
|
serverMux *http.ServeMux
|
|
|
|
|
|
|
|
server *http.Server
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
conns []*concurrentConn
|
|
|
|
conns []*concurrentConn
|
|
|
|
connsMu sync.RWMutex
|
|
|
|
connsMu sync.RWMutex
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func NewWebAddon() *WebAddon {
|
|
|
|
func NewWebAddon(addr string) *WebAddon {
|
|
|
|
web := new(WebAddon)
|
|
|
|
web := new(WebAddon)
|
|
|
|
web.addr = ":9081"
|
|
|
|
|
|
|
|
web.upgrader = &websocket.Upgrader{
|
|
|
|
web.upgrader = &websocket.Upgrader{
|
|
|
|
CheckOrigin: func(r *http.Request) bool {
|
|
|
|
CheckOrigin: func(r *http.Request) bool {
|
|
|
|
return true
|
|
|
|
return true
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
web.serverMux = new(http.ServeMux)
|
|
|
|
serverMux := new(http.ServeMux)
|
|
|
|
web.serverMux.HandleFunc("/echo", web.echo)
|
|
|
|
serverMux.HandleFunc("/echo", web.echo)
|
|
|
|
|
|
|
|
|
|
|
|
// web.serverMux.Handle("/", http.FileServer(http.Dir("addon/web/client/build")))
|
|
|
|
|
|
|
|
fsys, err := fs.Sub(assets, "client/build")
|
|
|
|
fsys, err := fs.Sub(assets, "client/build")
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
web.serverMux.Handle("/", http.FileServer(http.FS(fsys)))
|
|
|
|
serverMux.Handle("/", http.FileServer(http.FS(fsys)))
|
|
|
|
|
|
|
|
|
|
|
|
web.server = &http.Server{Addr: web.addr, Handler: web.serverMux}
|
|
|
|
server := &http.Server{Addr: addr, Handler: serverMux}
|
|
|
|
log = log.WithField("in", "WebAddon")
|
|
|
|
log = log.WithField("in", "WebAddon")
|
|
|
|
web.conns = make([]*concurrentConn, 0)
|
|
|
|
web.conns = make([]*concurrentConn, 0)
|
|
|
|
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
go func() {
|
|
|
|
log.Infof("server start listen at %v\n", web.addr)
|
|
|
|
log.Infof("web interface start listen at %v\n", addr)
|
|
|
|
err := web.server.ListenAndServe()
|
|
|
|
err := server.ListenAndServe()
|
|
|
|
log.Error(err)
|
|
|
|
log.Error(err)
|
|
|
|
}()
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
|
|