From 3ed878ab461fee90228c6bbebccce3466e5ab3c3 Mon Sep 17 00:00:00 2001 From: paranarimasu <33796518+paranarimasu@users.noreply.github.com> Date: Tue, 7 Jun 2022 09:56:46 -0500 Subject: [PATCH] fix: allow configurable domain and prefix for all supported routes (#393) * fix: allow configurable domain and prefix for all supported routes * style: fix StyleCI finding --- .env.example | 38 +++++++++---------- .../Middleware/RedirectIfAuthenticated.php | 3 +- app/Providers/RouteServiceProvider.php | 2 + config/cors.php | 4 +- config/fortify.php | 13 ++++++- config/jetstream.php | 15 ++++++++ config/nova.php | 8 ++-- config/web.php | 24 ++++++++++++ config/wiki.php | 14 +++++++ resources/views/layouts/footer.blade.php | 4 +- routes/web.php | 2 - .../Actions/Fortify/AuthenticationTest.php | 6 +-- .../Actions/Fortify/EmailVerificationTest.php | 2 +- .../Fortify/PasswordConfirmationTest.php | 6 +-- .../Actions/Fortify/PasswordResetTest.php | 13 +++---- 15 files changed, 106 insertions(+), 48 deletions(-) create mode 100644 config/web.php diff --git a/.env.example b/.env.example index 95678126d..2a2f07266 100644 --- a/.env.example +++ b/.env.example @@ -20,8 +20,6 @@ PUSHER_APP_SECRET= PUSHER_APP_ID= PUSHER_APP_CLUSTER=mt1 ABLY_KEY= -MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" -MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" # cache CACHE_DRIVER=file @@ -70,17 +68,6 @@ ELASTIC_SCOUT_DRIVER_REFRESH_DOCUMENTS=false # elastic migrations ELASTIC_MIGRATIONS_TABLE=elastic_migrations -# enlightn -ENLIGHTN_SKIP_ENVIRONMENT_SPECIFIC=false -ENLIGHTN_USERNAME= -ENLIGHTN_API_TOKEN= -ENLIGHTN_GITHUB_REPO= - -# feature flags -ALLOW_VIDEO_STREAMS=false -ALLOW_DISCORD_NOTIFICATIONS=false -ALLOW_VIEW_RECORDING=false - # filesystems FILESYSTEM_DISK=local @@ -103,6 +90,15 @@ VIDEO_STREAM_READS= VIDEO_DISABLE_ASSERTS= VIDEO_VISIBILITY= +# flags +ALLOW_VIDEO_STREAMS=false +ALLOW_DISCORD_NOTIFICATIONS=false +ALLOW_VIEW_RECORDING=false + +# fortify +FORTIFY_PATH= +FORTIFY_URL=http://localhost + # hashing BCRYPT_ROUNDS=10 @@ -111,7 +107,8 @@ HORIZON_DOMAIN= HORIZON_PATH=horizon # jetstream -TEAM_CREATOR_ID= +JETSTREAM_PATH= +JETSTREAM_URL=http://localhost # logging LOG_CHANNEL=daily @@ -127,7 +124,7 @@ MAIL_USERNAME=null MAIL_PASSWORD=null MAIL_FROM_ADDRESS=null MAIL_FROM_NAME="${APP_NAME}" -MAIL_SENDMAIL_PATH=/usr/sbin/sendmail +MAIL_SENDMAIL_PATH="/usr/sbin/sendmail -bs -i" MAIL_LOG_CHANNEL= # nova @@ -176,11 +173,6 @@ SESSION_STORE=null SESSION_DOMAIN=null SESSION_SECURE_COOKIE= -# teams -HORIZON_TEAM_ID= -NOVA_TEAM_ID= -TELESCOPE_TEAM_ID= - # telescope TELESCOPE_DOMAIN=null TELESCOPE_PATH=telescope @@ -191,6 +183,12 @@ TELESCOPE_ENABLED=true VIDEO_PATH=/video VIDEO_URL= +# web +WEB_URL=http://localhost +WEB_PATH= + # wiki WIKI_FEATURED_ENTRY= WIKI_FEATURED_VIDEO= +WIKI_DONATE_URL=# +WIKI_FAQ_URL=# diff --git a/app/Http/Middleware/RedirectIfAuthenticated.php b/app/Http/Middleware/RedirectIfAuthenticated.php index 7ebe270b2..ecaeb9a7c 100644 --- a/app/Http/Middleware/RedirectIfAuthenticated.php +++ b/app/Http/Middleware/RedirectIfAuthenticated.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace App\Http\Middleware; -use App\Providers\RouteServiceProvider; use Closure; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; @@ -30,7 +29,7 @@ class RedirectIfAuthenticated foreach ($guards as $guard) { if (Auth::guard($guard)->check()) { - return redirect(RouteServiceProvider::HOME); + return to_route('dashboard'); } } diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index 76818d0d5..b9f4c8aa6 100644 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -50,6 +50,8 @@ class RouteServiceProvider extends ServiceProvider $this->routes(function () { Route::middleware('web') + ->domain(Config::get('web.url')) + ->prefix(Config::get('web.path')) ->group(base_path('routes/web.php')); Route::middleware('web') diff --git a/config/cors.php b/config/cors.php index ec8d2d85e..df46f5cfc 100644 --- a/config/cors.php +++ b/config/cors.php @@ -17,13 +17,13 @@ return [ | */ - 'paths' => ['api/*', 'sanctum/csrf-cookie'], + 'paths' => ['*'], 'allowed_methods' => ['*'], 'allowed_origins' => ['*'], - 'allowed_origins_patterns' => [], + 'allowed_origins_patterns' => ['*'], 'allowed_headers' => ['*'], diff --git a/config/fortify.php b/config/fortify.php index 7502779ec..2844bdb59 100644 --- a/config/fortify.php +++ b/config/fortify.php @@ -76,9 +76,9 @@ return [ | */ - 'prefix' => '', + 'prefix' => env('FORTIFY_PATH'), - 'domain' => null, + 'domain' => env('FORTIFY_URL'), /* |-------------------------------------------------------------------------- @@ -124,6 +124,15 @@ return [ 'views' => true, + 'redirects' => [ + 'login' => null, + 'logout' => env('FORTIFY_URL').env('FORTIFY_PATH').'/login', + 'password-confirmation' => null, + 'register' => null, + 'email-verification' => null, + 'password-reset' => null, + ], + /* |-------------------------------------------------------------------------- | Features diff --git a/config/jetstream.php b/config/jetstream.php index 286239872..88884e53d 100644 --- a/config/jetstream.php +++ b/config/jetstream.php @@ -52,6 +52,21 @@ return [ Features::accountDeletion(), ], + /* + |-------------------------------------------------------------------------- + | Jetstream Routes Prefix / Subdomain + |-------------------------------------------------------------------------- + | + | Here you may specify which prefix Jetstream will assign to all the routes + | that it registers with the application. If necessary, you may change + | subdomain under which all of the Jetstream routes will be available. + | + */ + + 'prefix' => env('JETSTREAM_PATH'), + + 'domain' => env('JETSTREAM_URL'), + /* |-------------------------------------------------------------------------- | Profile Photo Disk diff --git a/config/nova.php b/config/nova.php index 6573ceb1d..7d3934eed 100644 --- a/config/nova.php +++ b/config/nova.php @@ -51,10 +51,10 @@ return [ 'domain' => env('NOVA_DOMAIN_NAME'), 'routes' => [ - 'login' => env('APP_URL').'/login', - 'logout' => env('APP_URL').'/logout', - 'forgot_password' => env('APP_URL').'/forgot-password', - 'reset_password' => env('APP_URL').'/reset-password', + 'login' => env('FORTIFY_URL').env('FORTIFY_PATH').'/login', + 'logout' => false, + 'forgot_password' => env('FORTIFY_URL').env('FORTIFY_PATH').'/forgot-password', + 'reset_password' => env('FORTIFY_URL').env('FORTIFY_PATH').'/reset-password', ], /* diff --git a/config/web.php b/config/web.php new file mode 100644 index 000000000..149e850a6 --- /dev/null +++ b/config/web.php @@ -0,0 +1,24 @@ + env('WEB_URL'), + + 'path' => env('WEB_PATH'), +]; diff --git a/config/wiki.php b/config/wiki.php index 93fff5b00..d2f8f13aa 100644 --- a/config/wiki.php +++ b/config/wiki.php @@ -20,4 +20,18 @@ return [ 'featured_entry' => (int) env('WIKI_FEATURED_ENTRY'), 'featured_video' => (int) env('WIKI_FEATURED_VIDEO'), + + /* + |-------------------------------------------------------------------------- + | Footer Links + |-------------------------------------------------------------------------- + | + | We have footer links that direct the user to pages that are handled by animethemes-web. + | Because we want to decouple dependencies between projects, we should just register the URLs here. + | + */ + + 'donate' => env('WIKI_DONATE_URL'), + + 'faq' => env('WIKI_FAQ_URL'), ]; diff --git a/resources/views/layouts/footer.blade.php b/resources/views/layouts/footer.blade.php index 17fa1901a..84f20ace3 100644 --- a/resources/views/layouts/footer.blade.php +++ b/resources/views/layouts/footer.blade.php @@ -2,9 +2,9 @@
Transparency | - Donate + Donate | - FAQ + FAQ
diff --git a/routes/web.php b/routes/web.php index c389d83b8..ac0e83536 100644 --- a/routes/web.php +++ b/routes/web.php @@ -19,8 +19,6 @@ use Spatie\RouteDiscovery\Discovery\Discover; Discover::controllers()->in(app_path('Http/Controllers/Auth')); Discover::controllers()->in(app_path('Http/Controllers/Billing')); -Route::redirect('/', url('/login')); - Route::middleware(['auth', 'verified'])->get('/dashboard', function () { return view('dashboard'); })->name('dashboard'); diff --git a/tests/Feature/Actions/Fortify/AuthenticationTest.php b/tests/Feature/Actions/Fortify/AuthenticationTest.php index 08a97f9f6..9943c9eac 100644 --- a/tests/Feature/Actions/Fortify/AuthenticationTest.php +++ b/tests/Feature/Actions/Fortify/AuthenticationTest.php @@ -20,7 +20,7 @@ class AuthenticationTest extends TestCase */ public function testLoginScreenCanBeRendered(): void { - $response = $this->get('/login'); + $response = $this->get(route('login')); $response->assertStatus(200); } @@ -34,7 +34,7 @@ class AuthenticationTest extends TestCase { $user = User::factory()->createOne(); - $response = $this->post('/login', [ + $response = $this->post(route('login'), [ 'email' => $user->email, 'password' => 'password', ]); @@ -52,7 +52,7 @@ class AuthenticationTest extends TestCase { $user = User::factory()->createOne(); - $this->post('/login', [ + $this->post(route('login'), [ 'email' => $user->email, 'password' => 'wrong-password', ]); diff --git a/tests/Feature/Actions/Fortify/EmailVerificationTest.php b/tests/Feature/Actions/Fortify/EmailVerificationTest.php index 8bc0000a5..5444a76c8 100644 --- a/tests/Feature/Actions/Fortify/EmailVerificationTest.php +++ b/tests/Feature/Actions/Fortify/EmailVerificationTest.php @@ -32,7 +32,7 @@ class EmailVerificationTest extends TestCase 'email_verified_at' => null, ]); - $response = $this->actingAs($user)->get('/email/verify'); + $response = $this->actingAs($user)->get(route('verification.notice')); $response->assertStatus(200); } diff --git a/tests/Feature/Actions/Fortify/PasswordConfirmationTest.php b/tests/Feature/Actions/Fortify/PasswordConfirmationTest.php index 29dd4de84..416722eb9 100644 --- a/tests/Feature/Actions/Fortify/PasswordConfirmationTest.php +++ b/tests/Feature/Actions/Fortify/PasswordConfirmationTest.php @@ -21,7 +21,7 @@ class PasswordConfirmationTest extends TestCase { $user = User::factory()->createOne(); - $response = $this->actingAs($user)->get('/user/confirm-password'); + $response = $this->actingAs($user)->get(route('password.confirm')); $response->assertStatus(200); } @@ -35,7 +35,7 @@ class PasswordConfirmationTest extends TestCase { $user = User::factory()->createOne(); - $response = $this->actingAs($user)->post('/user/confirm-password', [ + $response = $this->actingAs($user)->post(route('password.confirm'), [ 'password' => 'password', ]); @@ -52,7 +52,7 @@ class PasswordConfirmationTest extends TestCase { $user = User::factory()->createOne(); - $response = $this->actingAs($user)->post('/user/confirm-password', [ + $response = $this->actingAs($user)->post(route('password.confirm'), [ 'password' => 'wrong-password', ]); diff --git a/tests/Feature/Actions/Fortify/PasswordResetTest.php b/tests/Feature/Actions/Fortify/PasswordResetTest.php index 4cd7e9634..8c5934572 100644 --- a/tests/Feature/Actions/Fortify/PasswordResetTest.php +++ b/tests/Feature/Actions/Fortify/PasswordResetTest.php @@ -29,7 +29,7 @@ class PasswordResetTest extends TestCase static::markTestSkipped('Password resets are not enabled.'); } - $response = $this->get('/forgot-password'); + $response = $this->get(route('password.request')); $response->assertStatus(200); } @@ -49,7 +49,7 @@ class PasswordResetTest extends TestCase $user = User::factory()->createOne(); - $this->post('/forgot-password', [ + $this->post(route('password.email'), [ 'email' => $user->email, ]); @@ -71,12 +71,12 @@ class PasswordResetTest extends TestCase $user = User::factory()->createOne(); - $this->post('/forgot-password', [ + $this->post(route('password.email'), [ 'email' => $user->email, ]); Notification::assertSentTo($user, ResetPassword::class, function (ResetPassword $notification) { - $response = $this->get('/reset-password/'.$notification->token); + $response = $this->get(route('password.reset', ['token' => $notification->token])); $response->assertStatus(200); @@ -99,15 +99,14 @@ class PasswordResetTest extends TestCase $user = User::factory()->createOne(); - $this->post('/forgot-password', [ + $this->post(route('password.email'), [ 'email' => $user->email, ]); $strongPassword = $this->faker->password(64, 128); Notification::assertSentTo($user, ResetPassword::class, function (ResetPassword $notification) use ($user, $strongPassword) { - $response = $this->post('/reset-password', [ - 'token' => $notification->token, + $response = $this->post(route('password.reset', ['token' => $notification->token]), [ 'email' => $user->email, 'password' => $strongPassword, 'password_confirmation' => $strongPassword,