factor out http server as middleware