Put all document fetching stuff in a middleware

Signed-off-by: Ian Macalinao <me@ian.pw>