diff --git a/config/dusk.php b/config/dusk.php new file mode 100644 index 000000000..dd72cc21a --- /dev/null +++ b/config/dusk.php @@ -0,0 +1,27 @@ + '_dusk', + + /* + |-------------------------------------------------------------------------- + | Dusk Domain + |-------------------------------------------------------------------------- + | + | This is the subdomain where Dusk will access its internal API routes. If this + | setting is null, Dusk will reside under the same domain as the + | application. Otherwise, this value will serve as the subdomain. + | + */ + + 'domain' => null, +]; diff --git a/src/Concerns/InteractsWithAuthentication.php b/src/Concerns/InteractsWithAuthentication.php index 7068f797b..f2736dcbc 100644 --- a/src/Concerns/InteractsWithAuthentication.php +++ b/src/Concerns/InteractsWithAuthentication.php @@ -28,7 +28,7 @@ public function loginAs($userId, $guard = null) { $userId = method_exists($userId, 'getKey') ? $userId->getKey() : $userId; - return $this->visit(rtrim('/_dusk/login/'.$userId.'/'.$guard, '/')); + return $this->visit(rtrim(route('dusk.login', ['userId' => $userId, 'guard' => $guard]))); } /** @@ -39,7 +39,7 @@ public function loginAs($userId, $guard = null) */ public function logout($guard = null) { - return $this->visit(rtrim('/_dusk/logout/'.$guard, '/')); + return $this->visit(rtrim(route('dusk.logout', ['guard' => $guard]), '/')); } /** @@ -50,7 +50,7 @@ public function logout($guard = null) */ protected function currentUserInfo($guard = null) { - $response = $this->visit("/_dusk/user/{$guard}"); + $response = $this->visit(route('dusk.user', ['guard' => $guard])); return json_decode(strip_tags($response->driver->getPageSource()), true); } diff --git a/src/DuskServiceProvider.php b/src/DuskServiceProvider.php index d969ba1dd..aaf245f4f 100644 --- a/src/DuskServiceProvider.php +++ b/src/DuskServiceProvider.php @@ -15,20 +15,26 @@ class DuskServiceProvider extends ServiceProvider public function boot() { if (! $this->app->environment('production')) { - Route::get('/_dusk/login/{userId}/{guard?}', [ + Route::group([ + 'prefix' => config('dusk.path'), + 'domain' => config('dusk.domain', null), 'middleware' => 'web', - 'uses' => 'Laravel\Dusk\Http\Controllers\UserController@login', - ]); + ], function () { + Route::get('/login/{userId}/{guard?}', [ + 'uses' => 'Laravel\Dusk\Http\Controllers\UserController@login', + 'as' => 'dusk.login', + ]); - Route::get('/_dusk/logout/{guard?}', [ - 'middleware' => 'web', - 'uses' => 'Laravel\Dusk\Http\Controllers\UserController@logout', - ]); + Route::get('/logout/{guard?}', [ + 'uses' => 'Laravel\Dusk\Http\Controllers\UserController@logout', + 'as' => 'dusk.logout', + ]); - Route::get('/_dusk/user/{guard?}', [ - 'middleware' => 'web', - 'uses' => 'Laravel\Dusk\Http\Controllers\UserController@user', - ]); + Route::get('/user/{guard?}', [ + 'uses' => 'Laravel\Dusk\Http\Controllers\UserController@user', + 'as' => 'dusk.user', + ]); + }); } } @@ -41,16 +47,23 @@ public function boot() */ public function register() { - if ($this->app->runningInConsole()) { - $this->commands([ - Console\InstallCommand::class, - Console\DuskCommand::class, - Console\DuskFailsCommand::class, - Console\MakeCommand::class, - Console\PageCommand::class, - Console\ComponentCommand::class, - Console\ChromeDriverCommand::class, - ]); + if (! $this->app->environment('production')) { + $this->mergeConfigFrom(__DIR__.'/../config/dusk.php', 'dusk'); + $this->publishes([ + __DIR__.'/../config/dusk.php' => config_path('dusk.php'), + ], 'dusk-config'); + + if ($this->app->runningInConsole()) { + $this->commands([ + Console\InstallCommand::class, + Console\DuskCommand::class, + Console\DuskFailsCommand::class, + Console\MakeCommand::class, + Console\PageCommand::class, + Console\ComponentCommand::class, + Console\ChromeDriverCommand::class, + ]); + } } } }