diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 6b2fdbf1..059aa0cc 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -48,14 +48,4 @@ class Kernel extends ConsoleKernel { $schedule->command('cachet:beacon')->twiceDaily(0, 12); } - - /** - * Register the Closure based commands for the application. - * - * @return void - */ - protected function commands() - { - require base_path('routes/console.php'); - } } diff --git a/app/Foundation/Providers/RouteServiceProvider.php b/app/Foundation/Providers/RouteServiceProvider.php index ad91ca50..c78f873f 100644 --- a/app/Foundation/Providers/RouteServiceProvider.php +++ b/app/Foundation/Providers/RouteServiceProvider.php @@ -11,8 +11,17 @@ namespace CachetHQ\Cachet\Foundation\Providers; +use Barryvdh\Cors\HandleCors; +use CachetHQ\Cachet\Http\Middleware\Acceptable; +use CachetHQ\Cachet\Http\Middleware\Timezone; +use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse; +use Illuminate\Cookie\Middleware\EncryptCookies; +use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken; use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; +use Illuminate\Routing\Middleware\SubstituteBindings; use Illuminate\Routing\Router; +use Illuminate\Session\Middleware\StartSession; +use Illuminate\View\Middleware\ShareErrorsFromSession; /** * This is the route service provider. @@ -35,34 +44,36 @@ class RouteServiceProvider extends ServiceProvider /** * Define the route model bindings, pattern filters, etc. * + * @return void + */ + public function boot() + { + parent::boot(); + + $this->app->call([$this, 'bind']); + } + + /** + * Define the bindings for the application. + * * @param \Illuminate\Routing\Router $router * * @return void */ - public function boot(Router $router) + public function bind(Router $router) { - parent::boot($router); - - $this->registerBindings(); - } - - /** - * Register model bindings. - * - * @return void - */ - protected function registerBindings() - { - $this->app->router->model('component', 'CachetHQ\Cachet\Models\Component'); - $this->app->router->model('component_group', 'CachetHQ\Cachet\Models\ComponentGroup'); - $this->app->router->model('incident', 'CachetHQ\Cachet\Models\Incident'); - $this->app->router->model('incident_template', 'CachetHQ\Cachet\Models\IncidentTemplate'); - $this->app->router->model('metric', 'CachetHQ\Cachet\Models\Metric'); - $this->app->router->model('metric_point', 'CachetHQ\Cachet\Models\MetricPoint'); - $this->app->router->model('setting', 'CachetHQ\Cachet\Models\Setting'); - $this->app->router->model('subscriber', 'CachetHQ\Cachet\Models\Subscriber'); - $this->app->router->model('subscription', 'CachetHQ\Cachet\Models\Subscription'); - $this->app->router->model('user', 'CachetHQ\Cachet\Models\User'); + $router->model('component', 'CachetHQ\Cachet\Models\Component'); + $router->model('component_group', 'CachetHQ\Cachet\Models\ComponentGroup'); + $router->model('incident', 'CachetHQ\Cachet\Models\Incident'); + $router->model('incident_template', 'CachetHQ\Cachet\Models\IncidentTemplate'); + $router->model('incident_update', 'CachetHQ\Cachet\Models\IncidentUpdate'); + $router->model('metric', 'CachetHQ\Cachet\Models\Metric'); + $router->model('metric_point', 'CachetHQ\Cachet\Models\MetricPoint'); + $router->model('setting', 'CachetHQ\Cachet\Models\Setting'); + $router->model('subscriber', 'CachetHQ\Cachet\Models\Subscriber'); + $router->model('subscription', 'CachetHQ\Cachet\Models\Subscription'); + $router->model('tag', 'CachetHQ\Cachet\Models\Tag'); + $router->model('user', 'CachetHQ\Cachet\Models\User'); } /** @@ -82,8 +93,60 @@ class RouteServiceProvider extends ServiceProvider $class = str_replace('/', '\\', $class); $class = substr($class, 0, -4); - $this->app->make("CachetHQ\\Cachet\\Http\\Routes${class}")->map($router); + $routes = $this->app->make("CachetHQ\\Cachet\\Http\\Routes${class}"); + + if ($routes::$browser) { + $this->mapForBrowser($router, $routes); + } else { + $this->mapOtherwise($router, $routes); + } } }); } + + /** + * Wrap the routes in the browser specific middleware. + * + * @param \Illuminate\Routing\Router $router + * @param object $routes + * + * @return void + */ + protected function mapForBrowser(Router $router, $routes) + { + $middleware = [ + EncryptCookies::class, + AddQueuedCookiesToResponse::class, + StartSession::class, + ShareErrorsFromSession::class, + VerifyCsrfToken::class, + SubstituteBindings::class, + ]; + + $router->group(['middleware' => $middleware], function (Router $router) use ($routes) { + $routes->map($router); + }); + } + + /** + * Wrap the routes in the basic middleware. + * + * @param \Illuminate\Routing\Router $router + * @param object $routes + * + * @return void + */ + protected function mapOtherwise(Router $router, $routes) + { + $middleware = [ + HandleCors::class, + SubstituteBindings::class, + Acceptable::class, + Timezone::class, + ]; + + $router->group(['middleware' => $middleware], function (Router $router) use ($routes) { + $routes->map($router); + }); + } } diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index 05d634c0..685f09df 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -25,27 +25,6 @@ class Kernel extends HttpKernel 'Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode', ]; - /** - * The application's route middleware groups. - * - * @var array - */ - protected $middlewareGroups = [ - 'web' => [ - 'Illuminate\Cookie\Middleware\EncryptCookies', - 'Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse', - 'Illuminate\Session\Middleware\StartSession', - 'Illuminate\View\Middleware\ShareErrorsFromSession', - \Illuminate\Routing\Middleware\SubstituteBindings::class, - 'Illuminate\Foundation\Http\Middleware\VerifyCsrfToken', - ], - 'api' => [ - 'Barryvdh\Cors\HandleCors', - 'CachetHQ\Cachet\Http\Middleware\Acceptable', - 'CachetHQ\Cachet\Http\Middleware\Timezone', - ], - ]; - /** * The application's route middleware. * @@ -53,8 +32,7 @@ class Kernel extends HttpKernel */ protected $routeMiddleware = [ 'admin' => 'CachetHQ\Cachet\Http\Middleware\Admin', - 'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class, - 'can' => \Illuminate\Auth\Middleware\Authorize::class, + 'can' => 'Illuminate\Auth\Middleware\Authorize', 'auth.api' => 'CachetHQ\Cachet\Http\Middleware\ApiAuthentication', 'guest' => 'CachetHQ\Cachet\Http\Middleware\RedirectIfAuthenticated', 'localize' => 'CachetHQ\Cachet\Http\Middleware\Localize', diff --git a/app/Http/Routes/ApiRoutes.php b/app/Http/Routes/ApiRoutes.php index 6bc32aa3..f255e317 100644 --- a/app/Http/Routes/ApiRoutes.php +++ b/app/Http/Routes/ApiRoutes.php @@ -20,6 +20,13 @@ use Illuminate\Contracts\Routing\Registrar; */ class ApiRoutes { + /** + * Defines if these routes are for the browser. + * + * @var bool + */ + public static $browser = false; + /** * Define the api routes. * @@ -32,7 +39,6 @@ class ApiRoutes $router->group([ 'namespace' => 'Api', 'prefix' => 'api/v1', - 'middleware' => ['api'], ], function (Registrar $router) { $router->group(['middleware' => ['auth.api']], function (Registrar $router) { $router->get('ping', 'GeneralController@ping'); diff --git a/app/Http/Routes/AuthRoutes.php b/app/Http/Routes/AuthRoutes.php index 0e9fdee5..f1dd7fa9 100644 --- a/app/Http/Routes/AuthRoutes.php +++ b/app/Http/Routes/AuthRoutes.php @@ -20,6 +20,13 @@ use Illuminate\Contracts\Routing\Registrar; */ class AuthRoutes { + /** + * Defines if these routes are for the browser. + * + * @var bool + */ + public static $browser = true; + /** * Define the auth routes. * @@ -30,7 +37,7 @@ class AuthRoutes public function map(Registrar $router) { $router->group([ - 'middleware' => ['web', 'ready'], + 'middleware' => ['ready'], 'prefix' => 'auth', ], function (Registrar $router) { $router->get('login', [ diff --git a/app/Http/Routes/Dashboard/ApiRoutes.php b/app/Http/Routes/Dashboard/ApiRoutes.php index 6b2567d5..a07f9c4a 100644 --- a/app/Http/Routes/Dashboard/ApiRoutes.php +++ b/app/Http/Routes/Dashboard/ApiRoutes.php @@ -21,6 +21,13 @@ use Illuminate\Contracts\Routing\Registrar; */ class ApiRoutes { + /** + * Defines if these routes are for the browser. + * + * @var bool + */ + public static $browser = true; + /** * Define the dashboard api routes. * @@ -31,7 +38,7 @@ class ApiRoutes public function map(Registrar $router) { $router->group([ - 'middleware' => ['web', 'auth'], + 'middleware' => ['auth'], 'namespace' => 'Dashboard', 'prefix' => 'dashboard/api', ], function (Registrar $router) { diff --git a/app/Http/Routes/Dashboard/BaseRoutes.php b/app/Http/Routes/Dashboard/BaseRoutes.php index cdb308f7..61d7e742 100644 --- a/app/Http/Routes/Dashboard/BaseRoutes.php +++ b/app/Http/Routes/Dashboard/BaseRoutes.php @@ -21,6 +21,13 @@ use Illuminate\Contracts\Routing\Registrar; */ class BaseRoutes { + /** + * Defines if these routes are for the browser. + * + * @var bool + */ + public static $browser = true; + /** * Define the dashboard base routes. * @@ -31,7 +38,7 @@ class BaseRoutes public function map(Registrar $router) { $router->group([ - 'middleware' => ['web', 'auth'], + 'middleware' => ['auth'], 'namespace' => 'Dashboard', ], function (Registrar $router) { $router->get('admin', 'DashboardController@redirectAdmin'); diff --git a/app/Http/Routes/Dashboard/ComponentRoutes.php b/app/Http/Routes/Dashboard/ComponentRoutes.php index 6cdbcaaa..ed14f1e1 100644 --- a/app/Http/Routes/Dashboard/ComponentRoutes.php +++ b/app/Http/Routes/Dashboard/ComponentRoutes.php @@ -21,6 +21,13 @@ use Illuminate\Contracts\Routing\Registrar; */ class ComponentRoutes { + /** + * Defines if these routes are for the browser. + * + * @var bool + */ + public static $browser = true; + /** * Define the dashboard component routes. * @@ -31,7 +38,7 @@ class ComponentRoutes public function map(Registrar $router) { $router->group([ - 'middleware' => ['web', 'auth'], + 'middleware' => ['auth'], 'namespace' => 'Dashboard', 'prefix' => 'dashboard/components', ], function (Registrar $router) { diff --git a/app/Http/Routes/Dashboard/IncidentRoutes.php b/app/Http/Routes/Dashboard/IncidentRoutes.php index d631f93b..c312bc08 100644 --- a/app/Http/Routes/Dashboard/IncidentRoutes.php +++ b/app/Http/Routes/Dashboard/IncidentRoutes.php @@ -21,6 +21,13 @@ use Illuminate\Contracts\Routing\Registrar; */ class IncidentRoutes { + /** + * Defines if these routes are for the browser. + * + * @var bool + */ + public static $browser = true; + /** * Define the dashboard incident routes. * @@ -31,7 +38,7 @@ class IncidentRoutes public function map(Registrar $router) { $router->group([ - 'middleware' => ['web', 'auth'], + 'middleware' => ['auth'], 'namespace' => 'Dashboard', 'prefix' => 'dashboard/incidents', ], function (Registrar $router) { diff --git a/app/Http/Routes/Dashboard/MetricRoutes.php b/app/Http/Routes/Dashboard/MetricRoutes.php index 7d59c043..3f28899d 100644 --- a/app/Http/Routes/Dashboard/MetricRoutes.php +++ b/app/Http/Routes/Dashboard/MetricRoutes.php @@ -21,6 +21,13 @@ use Illuminate\Contracts\Routing\Registrar; */ class MetricRoutes { + /** + * Defines if these routes are for the browser. + * + * @var bool + */ + public static $browser = true; + /** * Define the dashboard metric routes. * @@ -31,7 +38,7 @@ class MetricRoutes public function map(Registrar $router) { $router->group([ - 'middleware' => ['web', 'auth'], + 'middleware' => ['auth'], 'namespace' => 'Dashboard', 'prefix' => 'dashboard/metrics', ], function (Registrar $router) { diff --git a/app/Http/Routes/Dashboard/ScheduleRoutes.php b/app/Http/Routes/Dashboard/ScheduleRoutes.php index 722ab8a0..506fe51b 100644 --- a/app/Http/Routes/Dashboard/ScheduleRoutes.php +++ b/app/Http/Routes/Dashboard/ScheduleRoutes.php @@ -21,6 +21,13 @@ use Illuminate\Contracts\Routing\Registrar; */ class ScheduleRoutes { + /** + * Defines if these routes are for the browser. + * + * @var bool + */ + public static $browser = true; + /** * Define the dashboard schedule routes. * @@ -31,7 +38,7 @@ class ScheduleRoutes public function map(Registrar $router) { $router->group([ - 'middleware' => ['web', 'auth'], + 'middleware' => ['auth'], 'namespace' => 'Dashboard', 'prefix' => 'dashboard/schedule', ], function (Registrar $router) { diff --git a/app/Http/Routes/Dashboard/SettingRoutes.php b/app/Http/Routes/Dashboard/SettingRoutes.php index c4050236..4370a750 100644 --- a/app/Http/Routes/Dashboard/SettingRoutes.php +++ b/app/Http/Routes/Dashboard/SettingRoutes.php @@ -21,6 +21,13 @@ use Illuminate\Contracts\Routing\Registrar; */ class SettingRoutes { + /** + * Defines if these routes are for the browser. + * + * @var bool + */ + public static $browser = true; + /** * Define the dashboard setting routes. * @@ -31,7 +38,7 @@ class SettingRoutes public function map(Registrar $router) { $router->group([ - 'middleware' => ['web', 'auth'], + 'middleware' => ['auth'], 'namespace' => 'Dashboard', 'prefix' => 'dashboard/settings', ], function (Registrar $router) { diff --git a/app/Http/Routes/Dashboard/SubscriberRoutes.php b/app/Http/Routes/Dashboard/SubscriberRoutes.php index 6e08e113..129d786f 100644 --- a/app/Http/Routes/Dashboard/SubscriberRoutes.php +++ b/app/Http/Routes/Dashboard/SubscriberRoutes.php @@ -21,6 +21,13 @@ use Illuminate\Contracts\Routing\Registrar; */ class SubscriberRoutes { + /** + * Defines if these routes are for the browser. + * + * @var bool + */ + public static $browser = true; + /** * Define the dashboard subscriber routes. * @@ -31,7 +38,7 @@ class SubscriberRoutes public function map(Registrar $router) { $router->group([ - 'middleware' => ['web', 'auth'], + 'middleware' => ['auth'], 'namespace' => 'Dashboard', 'prefix' => 'dashboard/subscribers', ], function (Registrar $router) { diff --git a/app/Http/Routes/Dashboard/TeamRoutes.php b/app/Http/Routes/Dashboard/TeamRoutes.php index db56141f..88728592 100644 --- a/app/Http/Routes/Dashboard/TeamRoutes.php +++ b/app/Http/Routes/Dashboard/TeamRoutes.php @@ -21,6 +21,13 @@ use Illuminate\Contracts\Routing\Registrar; */ class TeamRoutes { + /** + * Defines if these routes are for the browser. + * + * @var bool + */ + public static $browser = true; + /** * Define the dashboard team routes. * @@ -31,7 +38,7 @@ class TeamRoutes public function map(Registrar $router) { $router->group([ - 'middleware' => ['web', 'auth'], + 'middleware' => ['auth'], 'namespace' => 'Dashboard', 'prefix' => 'dashboard/team', ], function (Registrar $router) { diff --git a/app/Http/Routes/Dashboard/TemplateRoutes.php b/app/Http/Routes/Dashboard/TemplateRoutes.php index 338de8a3..289f9752 100644 --- a/app/Http/Routes/Dashboard/TemplateRoutes.php +++ b/app/Http/Routes/Dashboard/TemplateRoutes.php @@ -21,6 +21,13 @@ use Illuminate\Contracts\Routing\Registrar; */ class TemplateRoutes { + /** + * Defines if these routes are for the browser. + * + * @var bool + */ + public static $browser = true; + /** * Define the dashboard template routes. * @@ -31,7 +38,7 @@ class TemplateRoutes public function map(Registrar $router) { $router->group([ - 'middleware' => ['web', 'auth'], + 'middleware' => ['auth'], 'namespace' => 'Dashboard', 'prefix' => 'dashboard/templates', ], function (Registrar $router) { diff --git a/app/Http/Routes/Dashboard/UserRoutes.php b/app/Http/Routes/Dashboard/UserRoutes.php index 6934a4a6..15720a46 100644 --- a/app/Http/Routes/Dashboard/UserRoutes.php +++ b/app/Http/Routes/Dashboard/UserRoutes.php @@ -21,6 +21,13 @@ use Illuminate\Contracts\Routing\Registrar; */ class UserRoutes { + /** + * Defines if these routes are for the browser. + * + * @var bool + */ + public static $browser = true; + /** * Define the dashboard user routes. * @@ -31,7 +38,7 @@ class UserRoutes public function map(Registrar $router) { $router->group([ - 'middleware' => ['web', 'auth'], + 'middleware' => ['auth'], 'namespace' => 'Dashboard', 'prefix' => 'dashboard/user', ], function (Registrar $router) { diff --git a/app/Http/Routes/FeedRoutes.php b/app/Http/Routes/FeedRoutes.php index b2971c45..2a4f930e 100644 --- a/app/Http/Routes/FeedRoutes.php +++ b/app/Http/Routes/FeedRoutes.php @@ -20,6 +20,13 @@ use Illuminate\Contracts\Routing\Registrar; */ class FeedRoutes { + /** + * Defines if these routes are for the browser. + * + * @var bool + */ + public static $browser = true; + /** * Define the status page routes. * @@ -30,7 +37,7 @@ class FeedRoutes public function map(Registrar $router) { $router->group([ - 'middleware' => ['web', 'ready'], + 'middleware' => ['ready'], ], function (Registrar $router) { $router->get('/atom/{component_group?}', [ 'as' => 'get:feed.atom', diff --git a/app/Http/Routes/SetupRoutes.php b/app/Http/Routes/SetupRoutes.php index a0ed0249..2558237c 100644 --- a/app/Http/Routes/SetupRoutes.php +++ b/app/Http/Routes/SetupRoutes.php @@ -21,6 +21,13 @@ use Illuminate\Contracts\Routing\Registrar; */ class SetupRoutes { + /** + * Defines if these routes are for the browser. + * + * @var bool + */ + public static $browser = true; + /** * Define the setup routes. * @@ -31,7 +38,7 @@ class SetupRoutes public function map(Registrar $router) { $router->group([ - 'middleware' => ['web', 'setup'], + 'middleware' => ['setup'], 'prefix' => 'setup', ], function (Registrar $router) { $router->get('/', [ diff --git a/app/Http/Routes/SignupRoutes.php b/app/Http/Routes/SignupRoutes.php index 1e0252cc..85307261 100644 --- a/app/Http/Routes/SignupRoutes.php +++ b/app/Http/Routes/SignupRoutes.php @@ -20,6 +20,13 @@ use Illuminate\Contracts\Routing\Registrar; */ class SignupRoutes { + /** + * Defines if these routes are for the browser. + * + * @var bool + */ + public static $browser = true; + /** * Define the signup routes. * @@ -30,7 +37,7 @@ class SignupRoutes public function map(Registrar $router) { $router->group([ - 'middleware' => ['web', 'ready', 'guest'], + 'middleware' => ['ready', 'guest'], 'prefix' => 'signup', ], function (Registrar $router) { $router->get('invite/{code}', [ diff --git a/app/Http/Routes/StatusPageRoutes.php b/app/Http/Routes/StatusPageRoutes.php index d8352739..05df54e7 100644 --- a/app/Http/Routes/StatusPageRoutes.php +++ b/app/Http/Routes/StatusPageRoutes.php @@ -20,6 +20,13 @@ use Illuminate\Contracts\Routing\Registrar; */ class StatusPageRoutes { + /** + * Defines if these routes are for the browser. + * + * @var bool + */ + public static $browser = true; + /** * Define the status page routes. * @@ -30,7 +37,7 @@ class StatusPageRoutes public function map(Registrar $router) { $router->group([ - 'middleware' => ['web', 'ready', 'localize'], + 'middleware' => ['ready', 'localize'], ], function (Registrar $router) { $router->get('/', [ 'as' => 'get:status-page', diff --git a/app/Http/Routes/SubscribeRoutes.php b/app/Http/Routes/SubscribeRoutes.php index 7eded56f..e844ba18 100644 --- a/app/Http/Routes/SubscribeRoutes.php +++ b/app/Http/Routes/SubscribeRoutes.php @@ -20,6 +20,13 @@ use Illuminate\Contracts\Routing\Registrar; */ class SubscribeRoutes { + /** + * Defines if these routes are for the browser. + * + * @var bool + */ + public static $browser = true; + /** * Define the subscribe routes. * @@ -30,7 +37,7 @@ class SubscribeRoutes public function map(Registrar $router) { $router->group([ - 'middleware' => ['web', 'ready', 'localize', 'subscribers'], + 'middleware' => ['ready', 'localize', 'subscribers'], ], function (Registrar $router) { $router->get('subscribe', [ 'as' => 'get:subscribe',