setRouteClass(DashedRoute::class); $routes->scope('/', function (RouteBuilder $builder) { $builder->setExtensions(['json']); // Register scoped middleware for in scopes. $builder->registerMiddleware('csrf', new CsrfProtectionMiddleware([ 'httponly' => 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); }); // API routes $routes->scope('/api', function (RouteBuilder $routes) { // $routes->applyMiddleware('ratelimit', 'auth.api'); $routes->scope('/v1', function (RouteBuilder $routes) { // $routes->applyMiddleware('v1compat'); $routes->setExtensions(['json']); // Generic API route $routes->connect('/{controller}/{action}/*'); // Tags plugin routes $routes->plugin( 'tags', ['path' => '/tags'], function ($routes) { $routes->setRouteClass(DashedRoute::class); $routes->connect( '/{action}/*', ['controller' => 'Tags'] ); } ); }); });