fix caching responses

This fixes a race condition that happened under high load due to the caching changes.  It's a fairly major change.

It adds connect and moves most concerns into middleware: cors headers, logging, and caching.  The cors caching has been extracted into a general-purpose thundering-herd-proof caching middleware.

It also adds tests via mocha and supertest.