How to add custom routes to core routes in Strapi 4

Hi, In Strapi 3 all routes were handled in the routes.json . When a new content type was added, all core routes were added to this routes.json automatically. When there was a need for an additional route, I could duplicate on of the existing routes and modify it.

Now with Strapi 4 the routes are not added to a routes file anymore, instead only a createCoreRouter() function is called which dynamically creates all core routes.

For modifying the routes, the Strapi 4 Documentation lists two ways:
First, modifying the core routes by adding a second paramater to this createCoreRouter() function.
Second, using a custom router and adding all routes manually.

However, I would like to use a combination of both. I want to use all core routes but additionally some custom ones e.g. “deleteAllExpired”.

Is there a way to create a custom additional route, without rebuilting the core routes manually? e.g. extending the createCoreRouter() function with some custom routes? I did not find an example on how to do this.

Thank you for your help.

Thanks for your great response; you saved my day.
I’m wondering how Strapi 5 doesn’t care about this issue!?