Separate version check and api-session into middleware