Skip to content

Commit

Permalink
force https at the boot level instead of in the route files
Browse files Browse the repository at this point in the history
  • Loading branch information
ildyria committed Dec 27, 2023
1 parent ea3dfb4 commit 97638fc
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 28 deletions.
8 changes: 8 additions & 0 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Str;
use Livewire\Livewire;
Expand Down Expand Up @@ -104,6 +105,13 @@ public function boot()
*/
JsonResource::withoutWrapping();

/**
* We force URL to HTTPS if requested in .env via APP_FORCE_HTTPS.
*/
if (config('app.force_https') === true) {
URL::forceScheme('https');
}

if (config('database.db_log_sql', false) === true) {
DB::listen(fn ($q) => $this->logSQL($q));
}
Expand Down
5 changes: 0 additions & 5 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Http\Controllers;

use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\URL;

/*
|--------------------------------------------------------------------------
Expand All @@ -16,10 +15,6 @@
|
*/

if (config('app.force_https')) {
URL::forceScheme('https');
}

/**
* ALBUMS.
*/
Expand Down
6 changes: 0 additions & 6 deletions routes/web-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use App\Http\Controllers\IndexController;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\URL;

/*
|--------------------------------------------------------------------------
Expand All @@ -16,11 +15,6 @@
| contains the "admin" middleware group. Now create something great!
|
*/

if (config('app.force_https')) {
URL::forceScheme('https');
}

Route::get('/phpinfo', [IndexController::class, 'phpinfo']);

Route::get('/Jobs', [JobController::class, 'view']);
Expand Down
6 changes: 0 additions & 6 deletions routes/web-install.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Http\Controllers\Install;

use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\URL;

/*
|--------------------------------------------------------------------------
Expand All @@ -15,11 +14,6 @@
| contains the "install" middleware group. Now create something great!
|
*/

if (config('app.force_https')) {
URL::forceScheme('https');
}

Route::get('install/', [WelcomeController::class, 'view'])->name('install-welcome');
Route::get('install/req', [RequirementsController::class, 'view'])->name('install-req');
Route::get('install/perm', [PermissionsController::class, 'view'])->name('install-perm');
Expand Down
6 changes: 0 additions & 6 deletions routes/web-livewire.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use App\Livewire\Components\Pages\Gallery\Search;
use App\Models\Configs;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\URL;

/*
|--------------------------------------------------------------------------
Expand All @@ -19,11 +18,6 @@
| contains the "web" middleware group. Now create something great!
|
*/

if (config('app.force_https')) {
URL::forceScheme('https');
}

Route::middleware(['installation:complete', 'migration:complete'])
->group(function () {
Route::prefix(config('app.livewire') === true ? '' : 'livewire')
Expand Down
5 changes: 0 additions & 5 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@
| contains the "web" middleware group. Now create something great!
|
*/

if (config('app.force_https')) {
URL::forceScheme('https');
}

Route::feeds();

// If we are using Livewire by default, we no longer need those routes.
Expand Down

0 comments on commit 97638fc

Please sign in to comment.