steampixel / simplePHPRouter

This is a simple and small single class PHP router that can handel the whole url routing for your project.
MIT License
406 stars 117 forks source link

Override all Routes/Maintenance Mode #56

Closed notrespire closed 2 years ago

notrespire commented 2 years ago

Would it be possible to create a maintenance mode route that would over write all other routes while enabled?

Including the new route in Index.php would supersede all other routes and return whatever you want. Commenting it out, or removing would restore function of the existing routes.

Thanks for this project! Super simple to use and learn from, especially for newer developers like myself.

steampixel commented 2 years ago

Hi, something like this?

if(debug) {
  // Define a single route that matches all requests
  Route::add('/(.*)', function() {
    echo 'Debug mode<br>';
  });
} else {
  // Define all not maintenance routes
  Route::add('/', function() {
    echo 'Welcome :-)';
  });
}
notrespire commented 2 years ago

You know what... For some reason, I had it in my head that regular PHP statements wouldn't work... Not sure why. Brain fart.

This worked perfectly. Thank you