split routing logic into a seperate App::main function and corrected wrongly applied DI for middleware