Update routes

This commit is contained in:
James Brooks
2016-10-19 12:28:54 +01:00
parent e5647022c7
commit a7e8ba3697
21 changed files with 231 additions and 75 deletions

View File

@@ -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');
}
}

View File

@@ -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);
});
}
}

View File

@@ -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',

View File

@@ -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');

View File

@@ -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', [

View File

@@ -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) {

View File

@@ -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');

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -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',

View File

@@ -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('/', [

View File

@@ -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}', [

View File

@@ -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',

View File

@@ -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',