mirror of
https://github.com/twofas/2fas-server.git
synced 2024-12-24 01:50:24 +01:00
websocket api: split connection handler per route
This commit is contained in:
parent
254ce8546c
commit
b8dd4c167a
@ -16,10 +16,8 @@ func NewRoutesHandler(handler *common.ConnectionHandler) *RoutesHandler {
|
||||
}
|
||||
|
||||
func GinRoutesHandler(routes *RoutesHandler, router *gin.Engine) {
|
||||
connectionHandler := routes.connectionHandler.Handle()
|
||||
|
||||
router.GET("/browser_extensions/:extension_id", connectionHandler)
|
||||
router.GET("/browser_extensions/:extension_id/2fa_requests/:token_request_id", connectionHandler)
|
||||
router.GET("/browser_extensions/:extension_id", routes.connectionHandler.Handler())
|
||||
router.GET("/browser_extensions/:extension_id/2fa_requests/:token_request_id", routes.connectionHandler.Handler())
|
||||
|
||||
router.GET("/health", func(c *gin.Context) {
|
||||
c.String(200, "")
|
||||
|
@ -35,7 +35,7 @@ func NewConnectionHandler() *ConnectionHandler {
|
||||
}
|
||||
}
|
||||
|
||||
func (h *ConnectionHandler) Handle() gin.HandlerFunc {
|
||||
func (h *ConnectionHandler) Handler() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
channel := c.Request.URL.Path
|
||||
|
||||
@ -81,7 +81,7 @@ func (h *ConnectionHandler) serveWs(hub *Hub, w http.ResponseWriter, r *http.Req
|
||||
<-time.After(disconnectAfter)
|
||||
|
||||
defer func() {
|
||||
logging.Info("Connection closed after", disconnectAfter, "minutes")
|
||||
logging.Info("Connection closed after", disconnectAfter)
|
||||
|
||||
client.hub.unregister <- client
|
||||
client.conn.Close()
|
||||
|
Loading…
Reference in New Issue
Block a user