abstract out middleware and server