Move generic ApiRoutes to a whitelisted routeprovider file

This commit is contained in:
Nico Stapelbroek
2018-02-04 13:22:21 +01:00
parent c8e6a8f7c3
commit 6881859e36
5 changed files with 58 additions and 12 deletions

View File

@@ -15,8 +15,9 @@ use Barryvdh\Cors\HandleCors;
use CachetHQ\Cachet\Http\Middleware\Acceptable; use CachetHQ\Cachet\Http\Middleware\Acceptable;
use CachetHQ\Cachet\Http\Middleware\Authenticate; use CachetHQ\Cachet\Http\Middleware\Authenticate;
use CachetHQ\Cachet\Http\Middleware\Timezone; use CachetHQ\Cachet\Http\Middleware\Timezone;
use CachetHQ\Cachet\Http\Routes\ApiSystemRoutes;
use CachetHQ\Cachet\Http\Routes\AuthRoutes; use CachetHQ\Cachet\Http\Routes\AuthRoutes;
use CachetHQ\Cachet\Http\Routes\Setup\ApiRoutes; use CachetHQ\Cachet\Http\Routes\Setup\ApiRoutes as ApiSetupRoutes;
use CachetHQ\Cachet\Http\Routes\SetupRoutes; use CachetHQ\Cachet\Http\Routes\SetupRoutes;
use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse; use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse;
use Illuminate\Cookie\Middleware\EncryptCookies; use Illuminate\Cookie\Middleware\EncryptCookies;
@@ -52,7 +53,12 @@ class RouteServiceProvider extends ServiceProvider
* *
* @var string[] * @var string[]
*/ */
protected $whitelistedAuthRoutes = [AuthRoutes::class, SetupRoutes::class, ApiRoutes::class]; protected $whitelistedAuthRoutes = [
AuthRoutes::class,
SetupRoutes::class,
ApiSystemRoutes::class,
ApiSetupRoutes::class
];
/** /**
* Define the route model bindings, pattern filters, etc. * Define the route model bindings, pattern filters, etc.

View File

@@ -41,10 +41,6 @@ class ApiRoutes
'prefix' => 'api/v1', 'prefix' => 'api/v1',
], function (Registrar $router) { ], function (Registrar $router) {
$router->group(['middleware' => ['auth.api']], function (Registrar $router) { $router->group(['middleware' => ['auth.api']], function (Registrar $router) {
$router->get('ping', 'GeneralController@ping');
$router->get('version', 'GeneralController@version');
$router->get('status', 'GeneralController@status');
$router->get('components', 'ComponentController@index'); $router->get('components', 'ComponentController@index');
$router->get('components/groups', 'ComponentGroupController@index'); $router->get('components/groups', 'ComponentGroupController@index');
$router->get('components/groups/{component_group}', 'ComponentGroupController@show'); $router->get('components/groups/{component_group}', 'ComponentGroupController@show');

View File

@@ -0,0 +1,50 @@
<?php
/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Cachet\Http\Routes;
use Illuminate\Contracts\Routing\Registrar;
/**
* This is the api routes class.
*
* @author James Brooks <james@alt-three.com>
*/
class ApiSystemRoutes
{
/**
* Defines if these routes are for the browser.
*
* @var bool
*/
public static $browser = false;
/**
* Define the api routes for the system status, ping and version.
*
* @param \Illuminate\Contracts\Routing\Registrar $router
*
* @return void
*/
public function map(Registrar $router)
{
$router->group([
'namespace' => 'Api',
'prefix' => 'api/v1',
], function (Registrar $router) {
$router->group(['middleware' => ['auth.api']], function (Registrar $router) {
$router->get('ping', 'GeneralController@ping');
$router->get('version', 'GeneralController@version');
$router->get('status', 'GeneralController@status');
});
});
}
}

View File

@@ -16,9 +16,6 @@ $(function () {
beforeSend: function (xhr) { beforeSend: function (xhr) {
xhr.setRequestHeader('Accept', 'application/json'); xhr.setRequestHeader('Accept', 'application/json');
// xhr.setRequestHeader('Content-Type', 'application/json; charset=utf-8'); // xhr.setRequestHeader('Content-Type', 'application/json; charset=utf-8');
if (typeof window.apiKey !== 'undefined') {
xhr.setRequestHeader('X-Cachet-Token', window.apiKey);
}
}, },
statusCode: { statusCode: {
401: function () { 401: function () {

View File

@@ -62,7 +62,4 @@
</body> </body>
@yield('js') @yield('js')
<script src="{{ mix('dist/js/all.js') }}"></script> <script src="{{ mix('dist/js/all.js') }}"></script>
<script type="text/javascript">
window.apiKey = "{{ auth()->user()->api_key }}";
</script>
</html> </html>