How do I Disable or Enable Routes from a scheduled worker?

I currently use a route and a worker to redirect users during a maintenance event. This works fine but it means I need to always enable or disable the route so that the route isn’t being used when we are not in maintenance mode.

I have a URL on our site that can return a value that indicates if the site is in maintenance. I would like to use a chron trigger to execute a worker periodically that checks if the site is in maintenance or not and if it is in maintenance enable the redirect route and when it is not disable the route.

I have everything working except the part where I enable or disable a route. I looked and I could not see a way to do this from worker code. Can someone please tell me if this is possible and direct me to documentation?

Thanks

1 Like