loadRoutes method

AppRoutes loadRoutes()

register the routes of the app routers and give them, without a server and without providers. dox route:list uses this. When config.openApi is on, the docs routes are in it too. Providers do not run, because their setup() may connect to a database or start a worker. So a route that a provider adds in setup() is not in the list.

It is safe to call more than once. The route list is empty before and after the call, so a later startServer starts clean. Call it only before startServer, never in a running app: it empties Route(), so the server would lose its routes.

Dox().initialize(appConfig);
AppRoutes routes = Dox().loadRoutes();

Implementation

AppRoutes loadRoutes() {
  _clearRoutes();
  try {
    _registerRoute();
    // like startProviders: the docs routes, when OpenAPI is on
    if (config.openApi.isEnabled) OpenApiDocument(config.openApi).register();
    Route route = Route();
    return AppRoutes(
      routes: List<RouteData>.of(route.routes),
      fallbacks: List<RouteData>.of(route.fallbacks),
      mounts: Map<String, RawRequestHandler>.of(route.mounts),
      mountsWithMiddleware: Set<String>.of(route.mountsWithMiddleware),
    );
  } finally {
    _clearRoutes();
  }
}