Merge pull request #2 from beyondcode/websockets-route

Websockets route
This commit is contained in:
Freek Van der Herten 2018-11-26 23:36:10 +01:00 committed by GitHub
commit 9879c1bdad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 39 deletions

View File

@ -29,22 +29,6 @@ return [
*/
'client_provider' => ConfigClientProvider::class,
'dashboard' => [
/*
* Path for the Websockets debug dashboard
*/
'path' => '/websockets',
/*
* Middleware that will be applied to the dashboard routes.
*/
'middleware' => [
'web',
Authorize::class,
],
],
/*
* This array contains the hosts of which you want to allow incoming requests.
* Leave this empty if you want to accepts requests from all hosts.

View File

@ -1,9 +0,0 @@
<?php
use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\AuthenticateDashboard;
use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\SendMessage;
use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\ShowDashboard;
Route::get('/', ShowDashboard::class);
Route::post('auth', AuthenticateDashboard::class);
Route::post('event', SendMessage::class);

View File

@ -3,6 +3,10 @@
namespace BeyondCode\LaravelWebSockets;
use BeyondCode\LaravelWebSockets\Dashboard\EventSubscriber;
use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\AuthenticateDashboard;
use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\SendMessage;
use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\ShowDashboard;
use BeyondCode\LaravelWebSockets\Dashboard\Http\Middleware\Authorize;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Route;
@ -14,13 +18,11 @@ class WebSocketsServiceProvider extends ServiceProvider
{
public function boot()
{
Route::middlewareGroup('websockets', config('websockets.dashboard.middleware', []));
$this->publishes([
__DIR__.'/../config/websockets.php' => base_path('config/websockets.php'),
], 'config');
$this->registerRoutes();
$this->registerRouteMacro();
$this->registerDashboardGate();
@ -33,21 +35,17 @@ class WebSocketsServiceProvider extends ServiceProvider
Event::subscribe(EventSubscriber::class);
}
protected function registerRoutes()
protected function registerRouteMacro()
{
Route::group($this->routeConfiguration(), function () {
$this->loadRoutesFrom(__DIR__.'/Dashboard/Http/routes.php');
Route::macro('websocketsDashboard', function($prefix = 'websockets') {
Route::prefix($prefix)->namespace('\\')->middleware(Authorize::class)->group(function() {
Route::get('/', ShowDashboard::class);
Route::post('auth', AuthenticateDashboard::class);
Route::post('event', SendMessage::class);
});
});
}
protected function routeConfiguration()
{
return [
'prefix' => config('websockets.dashboard.path'),
'middleware' => 'websockets',
];
}
public function register()
{
$this->mergeConfigFrom(__DIR__.'/../config/websockets.php', 'websockets');