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:
18
wings.go
18
wings.go
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user