diff --git a/.env.production.example b/.env.production.example index bba4bfe..3478f1e 100644 --- a/.env.production.example +++ b/.env.production.example @@ -2,7 +2,7 @@ APP_NAME=Hoshpoint APP_ENV=production APP_KEY= APP_DEBUG=false -APP_URL=https://example.com +APP_URL=https://hoshpoint-api.treenix.ir HTTP_PORT=8080 APP_LOCALE=fa diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index e654229..6d0511d 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -14,6 +14,7 @@ use App\Policies\UserPolicy; use App\Policies\WalletPolicy; use App\Policies\WalletTransactionPolicy; use Illuminate\Support\Facades\Gate; +use Illuminate\Support\Facades\URL; use Illuminate\Support\ServiceProvider; class AppServiceProvider extends ServiceProvider @@ -31,6 +32,10 @@ class AppServiceProvider extends ServiceProvider */ public function boot(): void { + if (app()->environment('production') || str_starts_with((string) config('app.url'), 'https://')) { + URL::forceScheme('https'); + } + User::observe(UserObserver::class); Gate::policy(User::class, UserPolicy::class); diff --git a/bootstrap/app.php b/bootstrap/app.php index 4b327d2..35c28ff 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -13,7 +13,14 @@ return Application::configure(basePath: dirname(__DIR__)) health: '/up', ) ->withMiddleware(function (Middleware $middleware): void { - // + $middleware->trustProxies( + at: '*', + headers: Request::HEADER_X_FORWARDED_FOR + | Request::HEADER_X_FORWARDED_HOST + | Request::HEADER_X_FORWARDED_PORT + | Request::HEADER_X_FORWARDED_PROTO + | Request::HEADER_X_FORWARDED_AWS_ELB, + ); }) ->withExceptions(function (Exceptions $exceptions): void { $exceptions->shouldRenderJsonWhen( diff --git a/config/l5-swagger.php b/config/l5-swagger.php index cbd98a0..47f917f 100644 --- a/config/l5-swagger.php +++ b/config/l5-swagger.php @@ -251,7 +251,7 @@ return [ * Edit to trust the proxy's ip address - needed for AWS Load Balancer * string[] */ - 'proxy' => false, + 'proxy' => env('L5_SWAGGER_BEHIND_PROXY', '*'), /* * Configs plugin allows to fetch external configs instead of passing them to SwaggerUIBundle. @@ -315,7 +315,7 @@ return [ * Constants which can be used in annotations */ 'constants' => [ - 'L5_SWAGGER_CONST_HOST' => env('L5_SWAGGER_CONST_HOST', 'http://my-default-host.com'), + 'L5_SWAGGER_CONST_HOST' => env('L5_SWAGGER_CONST_HOST', env('APP_URL', 'http://localhost')), ], ], ]; diff --git a/docker/nginx/default.conf b/docker/nginx/default.conf index 3a1d67c..8747e18 100644 --- a/docker/nginx/default.conf +++ b/docker/nginx/default.conf @@ -39,6 +39,9 @@ server { fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; fastcgi_param DOCUMENT_ROOT $realpath_root; + fastcgi_param HTTP_X_FORWARDED_PROTO $http_x_forwarded_proto; + fastcgi_param HTTP_X_FORWARDED_FOR $proxy_add_x_forwarded_for; + fastcgi_param HTTP_X_FORWARDED_HOST $http_x_forwarded_host; include fastcgi_params; fastcgi_hide_header X-Powered-By; }