Clean up and generalize real-time serving.

Lots of refactoring, new middleware for handling cross-origin
real-time requests.