I would actually switch this to just return the list of routes and have your calling file/method create the application that these routes are passed to. That way this file really only does create the routes and your main file just creates the apps that consume the routes.