首次提交

master
lion 1 month ago
parent c1fb32067e
commit 5bd846ae62

@ -12,7 +12,7 @@ class TrustProxies extends Middleware
*
* @var array<int, string>|string|null
*/
protected $proxies = '*';
protected $proxies;
/**
* The headers that should be used to detect proxies.
@ -25,4 +25,12 @@ class TrustProxies extends Middleware
Request::HEADER_X_FORWARDED_PORT |
Request::HEADER_X_FORWARDED_PROTO |
Request::HEADER_X_FORWARDED_AWS_ELB;
public function handle($request, \Closure $next)
{
// 本地 APP_URL 为 http 时不信任 X-Forwarded-Proto,避免首页/登录链接被拼成 https
$this->proxies = str_starts_with((string) config('app.url'), 'https://') ? '*' : [];
return parent::handle($request, $next);
}
}

@ -27,7 +27,7 @@ class AppServiceProvider extends ServiceProvider
*/
public function boot(): void
{
if (app()->environment('production') || str_starts_with((string) config('app.url'), 'https://')) {
if (str_starts_with((string) config('app.url'), 'https://')) {
URL::forceScheme('https');
}
}

Loading…
Cancel
Save