App usual fix in app service provider

This commit is contained in:
Jérémy Munsch 2022-03-08 09:45:55 +01:00
parent 283a357281
commit b4ebf0549f
No known key found for this signature in database
GPG key ID: 55196BEE445F6049

View file

@ -3,7 +3,9 @@
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Http\Request;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\URL;
class AppServiceProvider extends ServiceProvider
{
@ -21,15 +23,27 @@ class AppServiceProvider extends ServiceProvider
*
* @return void
*/
public function boot(Request $request)
public function boot()
{
$proxy_url = env('PROXY_URL');
$host = $request->getHost();
if ($this->app->environment('dev')) {
\URL::forceScheme('https');
} elseif ($this->app->environment('production')) {
\URL::forceRootUrl($proxy_url);
\URL::forceScheme('https');
// * LOCAL HTTPS FIX
if (!in_array(config('app.env'), ['local', 'testing'])) {
URL::forceScheme('https');
}
// * HA PROXY FIX
App::singleton('clientIp', function () {
if (config('app.env') === 'local') {
return request()->getClientIp();
} else {
return request()->server('HTTP_X_FORWARDED_FOR') ??
request()->getClientIp();
}
});
// * LOCAL FORCE eg: for Carbon
setlocale(LC_ALL, \sprintf(
'%s_%s.UTF-8',
config('app.locale'),
\strtoupper(config('app.locale'))
));
Carbon::setLocale(config('app.locale'));
}
}