Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Commit 9879c1b

Browse files
authored
Merge pull request #2 from beyondcode/websockets-route
Websockets route
2 parents ad97ca5 + 901db40 commit 9879c1b

File tree

3 files changed

+12
-39
lines changed

3 files changed

+12
-39
lines changed

config/websockets.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,6 @@
2929
*/
3030
'client_provider' => ConfigClientProvider::class,
3131

32-
'dashboard' => [
33-
34-
/*
35-
* Path for the Websockets debug dashboard
36-
*/
37-
'path' => '/websockets',
38-
39-
/*
40-
* Middleware that will be applied to the dashboard routes.
41-
*/
42-
'middleware' => [
43-
'web',
44-
Authorize::class,
45-
],
46-
],
47-
4832
/*
4933
* This array contains the hosts of which you want to allow incoming requests.
5034
* Leave this empty if you want to accepts requests from all hosts.

src/Dashboard/Http/routes.php

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/WebSocketsServiceProvider.php

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
namespace BeyondCode\LaravelWebSockets;
44

55
use BeyondCode\LaravelWebSockets\Dashboard\EventSubscriber;
6+
use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\AuthenticateDashboard;
7+
use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\SendMessage;
8+
use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\ShowDashboard;
9+
use BeyondCode\LaravelWebSockets\Dashboard\Http\Middleware\Authorize;
610
use Illuminate\Support\Facades\Event;
711
use Illuminate\Support\Facades\Gate;
812
use Illuminate\Support\Facades\Route;
@@ -14,13 +18,11 @@ class WebSocketsServiceProvider extends ServiceProvider
1418
{
1519
public function boot()
1620
{
17-
Route::middlewareGroup('websockets', config('websockets.dashboard.middleware', []));
18-
1921
$this->publishes([
2022
__DIR__.'/../config/websockets.php' => base_path('config/websockets.php'),
2123
], 'config');
2224

23-
$this->registerRoutes();
25+
$this->registerRouteMacro();
2426

2527
$this->registerDashboardGate();
2628

@@ -33,21 +35,17 @@ public function boot()
3335
Event::subscribe(EventSubscriber::class);
3436
}
3537

36-
protected function registerRoutes()
38+
protected function registerRouteMacro()
3739
{
38-
Route::group($this->routeConfiguration(), function () {
39-
$this->loadRoutesFrom(__DIR__.'/Dashboard/Http/routes.php');
40+
Route::macro('websocketsDashboard', function($prefix = 'websockets') {
41+
Route::prefix($prefix)->namespace('\\')->middleware(Authorize::class)->group(function() {
42+
Route::get('/', ShowDashboard::class);
43+
Route::post('auth', AuthenticateDashboard::class);
44+
Route::post('event', SendMessage::class);
45+
});
4046
});
4147
}
4248

43-
protected function routeConfiguration()
44-
{
45-
return [
46-
'prefix' => config('websockets.dashboard.path'),
47-
'middleware' => 'websockets',
48-
];
49-
}
50-
5149
public function register()
5250
{
5351
$this->mergeConfigFrom(__DIR__.'/../config/websockets.php', 'websockets');

0 commit comments

Comments
 (0)