fix: 強制應用層 HTTPS (解決 Mixed Content 分頁問題)
This commit is contained in:
@@ -18,9 +18,17 @@ class AppServiceProvider extends ServiceProvider
|
||||
|
||||
public function boot(): void
|
||||
{
|
||||
// 如果是在正式環境或 APP_URL 是 https,強制轉為 https
|
||||
if ($this->app->environment('production') || str_contains(config('app.url'), 'https')) {
|
||||
// 強制 HTTPS 檢測邏輯 (包含 Cloudflare/Load Balancer 支援)
|
||||
$isHttps = $this->app->environment('production')
|
||||
|| str_contains(config('app.url'), 'https')
|
||||
|| request()->header('x-forwarded-proto') === 'https'
|
||||
|| request()->server('HTTPS') === 'on';
|
||||
|
||||
if ($isHttps) {
|
||||
URL::forceScheme('https');
|
||||
|
||||
// 強制讓 Request 物件認為自己是安全連線 (解決 Paginator 或 Request::secure() 判斷問題)
|
||||
request()->server->set('HTTPS', 'on');
|
||||
}
|
||||
|
||||
// 隱含授權:讓 "super-admin" 角色擁有所有權限
|
||||
|
||||
Reference in New Issue
Block a user