Add basic working websocket support

Specifically moving away from Socketio because the websockets can handle everything we need, and theres no updated go socketio libraries, so its a nightmare.
This commit is contained in:
Dane Everitt
2019-04-19 23:29:52 -07:00
parent 91ffc96c15
commit 1dfcebc746
3 changed files with 57 additions and 29 deletions

View File

@@ -3,6 +3,7 @@ package main
import (
"flag"
"fmt"
"github.com/gorilla/websocket"
"github.com/pterodactyl/wings/config"
"github.com/pterodactyl/wings/server"
"go.uber.org/zap"
@@ -71,18 +72,15 @@ func main() {
r := &Router{
Servers: servers,
token: c.AuthenticationToken,
upgrader: websocket.Upgrader{
// Ensure that the websocket request is originating from the Panel itself,
// and not some other location.
CheckOrigin: func(r *http.Request) bool {
return r.Header.Get("Origin") == c.PanelLocation
},
},
}
if sock, err := r.ConfigureWebsocket(); err != nil {
zap.S().Fatalw("failed to configure websocket", zap.Error(err))
return
} else {
r.Socketio = sock
}
defer r.Socketio.Close()
go r.Socketio.Serve()
router := r.ConfigureRouter()
zap.S().Infow("configuring webserver", zap.String("host", c.Api.Host), zap.Int("port", c.Api.Port))
if err := http.ListenAndServe(fmt.Sprintf("%s:%d", c.Api.Host, c.Api.Port), router); err != nil {