middleware and websocket stuff