Repository: strapi/strapi
File: packages/core/core/src/services/server/register-routes.ts (TypeScript)

Code before:

    const generateRouteScope = createRouteScopeGenerator(`plugin::${pluginName}`);

    if (Array.isArray(plugin.routes)) {
      plugin.routes.forEach((route) => {
        generateRouteScope(route);
        route.info = { pluginName };
      });
      strapi.contentAPI.applyExtraParamsToRoutes(plugin.routes);

      strapi.server.routes({
        type: 'admin',
        prefix: `/${pluginName}`,
        routes: plugin.routes,
      });
    } else {
      // Instantiate function-like routers
      // Mutate plugin.routes in-place and make sure router factories are instantiated correctly
      plugin.routes = instantiateRouterInputs(plugin.routes, strapi);

      _.forEach(plugin.routes, (router) => {
        router.type = router.type ?? 'admin';
        router.prefix = router.prefix ?? `/${pluginName}`;
        router.routes.forEach((route) => {
          generateRouteScope(route);
          route.info = {
            pluginName,
            ...(router.type === 'content-api' ? { type: 'content-api' as const } : {}),
          };
        });
        strapi.contentAPI.applyExtraParamsToRoutes(router.routes ?? []);

        strapi.server.routes(router);
      });
    }
  }
};

/**
 * Register api routes
 */
const registerAPIRoutes = (strapi: Core.Strapi) => {
  for (const apiName of Object.keys(strapi.apis)) {
    const api = strapi.api(apiName);

    const generateRouteScope = createRouteScopeGenerator(`api::${apiName}`);

    // Mutate api.routes in-place and make sure router factories are instantiated correctly
    api.routes = instantiateRouterInputs(api.routes, strapi);

    _.forEach(api.routes, (router) => {

Review comment (suggestion):
So we consider route.info to be undefined up to that point, right? So we don't spread a potential previous value in it.

Code after:

    const generateRouteScope = createRouteScopeGenerator(`plugin::${pluginName}`);

    if (Array.isArray(plugin.routes)) {
      plugin.routes.forEach((route) => {
        generateRouteScope(route);
        route.info = { pluginName };
      });
      strapi.contentAPI.applyExtraParamsToRoutes(plugin.routes);

      strapi.server.routes({
        type: 'admin',
        prefix: `/${pluginName}`,
        routes: plugin.routes,
      });
    } else {
      // Instantiate function-like routers
      // Mutate plugin.routes in-place and make sure router factories are instantiated correctly
      plugin.routes = instantiateRouterInputs(plugin.routes, strapi);

      _.forEach(plugin.routes, (router) => {
        router.type = router.type ?? 'admin';
        router.prefix = router.prefix ?? `/${pluginName}`;
        router.routes.forEach((route) => {
          generateRouteScope(route);
          route.info = { pluginName };
        });
        strapi.contentAPI.applyExtraParamsToRoutes(router.routes ?? []);

        strapi.server.routes(router);
      });
    }
  }
};

/**
 * Register api routes
 */
const registerAPIRoutes = (strapi: Core.Strapi) => {
  for (const apiName of Object.keys(strapi.apis)) {
    const api = strapi.api(apiName);

    const generateRouteScope = createRouteScopeGenerator(`api::${apiName}`);

    // Mutate api.routes in-place and make sure router factories are instantiated correctly
    api.routes = instantiateRouterInputs(api.routes, strapi);

    _.forEach(api.routes, (router) => {
      // TODO: remove once auth setup
      // pass meta down to compose endpoint
      router.type = 'content-api';