setRouteClass(DashedRoute::class); $routes->scope('/', function (RouteBuilder $builder) { $builder->setExtensions(['json', 'csv']); // Register scoped middleware for in scopes. $builder->registerMiddleware('csrf', new CsrfProtectionMiddleware([ 'httponly' => true, 'secure' => true, ])); /* * Apply a middleware to the current route scope. * Requires middleware to be registered through `Application::routes()` with `registerMiddleware()` * Dirty way of disabling the middleware if the AUTHORIZATION header is set */ if (empty($_SERVER['HTTP_AUTHORIZATION'])) { $builder->applyMiddleware('csrf'); } /* * Here, we are connecting '/' (base path) to a controller called 'Pages', * its action called 'display', and we pass a param to select the view file * to use (in this case, templates/Pages/home.php)... */ $builder->connect('/', ['controller' => 'Instance', 'action' => 'home']); /* * ...and connect the rest of 'Pages' controller's URLs. */ $builder->connect('/pages/*', ['controller' => 'Pages', 'action' => 'display']); /* * Connect catchall routes for all controllers. * * The `fallbacks` method is a shortcut for * * ``` * $builder->connect('/:controller', ['action' => 'index']); * $builder->connect('/:controller/:action/*', []); * ``` * * You can remove these routes once you've connected the * routes you want in your application. */ $builder->fallbacks(); }); $routes->prefix('Open', function (RouteBuilder $routes) { $routes->setExtensions(['json']); $routes->fallbacks(DashedRoute::class); }); /* * If you need a different set of middleware or none at all, * open new scope and define routes there. * * ``` * $routes->scope('/api', function (RouteBuilder $builder) { * // No $builder->applyMiddleware() here. * // Connect API actions here. * }); * ``` */