Exit server when browser tab is closed.

Use WebSocket to check when page is closed.
Also use http.CloseNotifier to stop when the request is cancelled.
Disable debug logging.