1. function matchScheduledApiEndpoints(endpoints) {
  2. const patterns = [
  3. /api\/schedule\/[a-zA-Z0-9_-]+/, // Basic schedule endpoint
  4. /api\/cron\/[a-zA-Z0-9_-]+/, // Cron schedule endpoint
  5. /api\/recurring\/[a-zA-Z0-9_-]+/, // Recurring schedule endpoint
  6. /api\/scheduled\/[a-zA-Z0-9_-]+/, // Another schedule endpoint
  7. /api\/task\/schedule\/[a-zA-Z0-9_-]+/, // Task scheduling
  8. ];
  9. for (const endpoint of endpoints) {
  10. for (const pattern of patterns) {
  11. if (new RegExp(pattern).test(endpoint)) {
  12. return { endpoint, pattern }; // Return the matching endpoint and pattern
  13. }
  14. }
  15. }
  16. return null; // No match found
  17. }
  18. //Example usage
  19. //const endpoints = ["/api/schedule/daily_report", "/api/cron/hourly_backup", "/api/some/other/endpoint"];
  20. //const match = matchScheduledApiEndpoints(endpoints);
  21. //if (match) {
  22. // console.log(`Endpoint "${match.endpoint}" matches pattern "${match.pattern}"`);
  23. //} else {
  24. // console.log("No matching endpoint found.");
  25. //}

Add your comment