websocket upgrade as router handler.

This commit is contained in:
Miroslav Šedivý
2021-09-18 14:59:15 +02:00
parent fd9d5ec6f8
commit f96466b7b9
3 changed files with 26 additions and 22 deletions

View File

@ -37,11 +37,9 @@ func New(WebSocketManager types.WebSocketManager, ApiManager types.ApiManager, c
router.Route("/api", ApiManager.Route)
router.Get("/api/ws", func(w http.ResponseWriter, r *http.Request) error {
return WebSocketManager.Upgrade(w, r, func(r *http.Request) bool {
return config.AllowOrigin(r.Header.Get("Origin"))
})
})
router.Get("/api/ws", WebSocketManager.Upgrade(func(r *http.Request) bool {
return config.AllowOrigin(r.Header.Get("Origin"))
}))
if config.Static != "" {
fs := http.FileServer(http.Dir(config.Static))