Earlier check for websocket environment.

This change stops the websocket handler from trying to handle routes that it shouldn't, e.g. if the user points their browser at a websocket endpoint.