// Function to get all routes
export function getAllRoutes(routesStack: any) {
  const routes: any = [];
  routesStack.stack.forEach((middleware: any) => {
    if (middleware.route) {
      // Route middleware
      const method = Object.keys(middleware.route.methods)[0].toUpperCase();
      const path = middleware.route.path;
      const regexp = middleware.regexp;
      routes.push({ method, path, regexp });
    } else if (middleware.name === 'router') {
      // Subrouter middleware (e.g., for routers mounted using app.use())
      middleware.handle.stack.forEach((handler: any) => {
        const method = Object.keys(handler.route.methods)[0].toUpperCase();
        const path = handler.route.path;
        const regexp = handler.regexp;
        routes.push({ method, path, regexp });
      });
    }
  });
  return routes;
}