From f9bdc8b124c7149f5f7e10d5dc8ec41eac415bd8 Mon Sep 17 00:00:00 2001 From: Manuel Riel Date: Wed, 23 Mar 2022 14:10:27 +0000 Subject: [PATCH] Add optional env var to force SSL --- README.md | 1 + app/Providers/RouteServiceProvider.php | 2 +- config/app.php | 1 + run.sh | 3 ++- 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c6d9cd0..8298752 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,7 @@ removed. docker run \ -p 8000:8000\ -e APP_URL=https://... \ + -e APP_FORCE_SSL=true \ -e DB_HOST=... \ -e DB_DATABASE=... \ -e DB_USERNAME=... \ diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index 3ee2b67..41aea58 100644 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -35,7 +35,7 @@ class RouteServiceProvider extends ServiceProvider */ public function boot() { - if (config('app.env') === 'production') { + if (config('app.force_ssl')) { \Illuminate\Support\Facades\URL::forceScheme('https'); } $this->configureRateLimiting(); diff --git a/config/app.php b/config/app.php index 6a3c4fd..88fa707 100644 --- a/config/app.php +++ b/config/app.php @@ -27,6 +27,7 @@ return [ */ 'env' => env('APP_ENV', 'production'), + 'force_ssl' => (bool) env('APP_FORCE_SSL', false), /* |-------------------------------------------------------------------------- diff --git a/run.sh b/run.sh index f314f75..0550d7c 100755 --- a/run.sh +++ b/run.sh @@ -13,7 +13,8 @@ DB_HOST=${DB_HOST} DB_DATABASE=${DB_DATABASE} DB_USERNAME=${DB_USERNAME} DB_PASSWORD=${DB_PASSWORD} -APP_URL=${APP_URL} +APP_URL=${APP_URL:-http://localhost:8000} +APP_FORCE_SSL=${APP_FORCE_SSL:-false} EOF php artisan key:generate --no-interaction --force fi