fix: 支援 Port 8081 直接訪問租戶 (IP-based tenancy support)
All checks were successful
Koori-ERP-Deploy-System / deploy-demo (push) Successful in 47s
Koori-ERP-Deploy-System / deploy-production (push) Has been skipped

This commit is contained in:
2026-01-16 08:58:32 +08:00
parent d28671b60c
commit c7e1154af8
3 changed files with 14 additions and 4 deletions

View File

@@ -17,7 +17,8 @@ class LoginController extends Controller
{
$centralDomains = config('tenancy.central_domains', []);
if (in_array(request()->getHost(), $centralDomains)) {
// [Hack] Demo 環境特殊規則Port 8081 強制視為租戶
if (request()->getPort() != 8081 && in_array(request()->getHost(), $centralDomains)) {
return Inertia::render('Landlord/Auth/Login');
}
@@ -43,7 +44,9 @@ class LoginController extends Controller
$request->session()->regenerate();
$centralDomains = config('tenancy.central_domains', []);
if (in_array($request->getHost(), $centralDomains)) {
$centralDomains = config('tenancy.central_domains', []);
// [Hack] Demo 環境特殊規則Port 8081 強制視為租戶
if ($request->getPort() != 8081 && in_array($request->getHost(), $centralDomains)) {
return redirect()->intended(route('landlord.dashboard'));
}

View File

@@ -19,13 +19,20 @@ class UniversalTenancy
// 判斷是否為中央域名
$centralDomains = config('tenancy.central_domains', []);
// [Hack] Demo 環境特殊規則:
// 如果是 8081 端口,強制視為租戶請求 (忽略中央域名檢查)
// 這樣可以讓 192.168.0.103:8081 直接訪問租戶,無需設定 hosts
if ($request->getPort() == 8081) {
return app(InitializeTenancyByDomain::class)->handle($request, $next);
}
if (in_array($request->getHost(), $centralDomains)) {
// 如果是中央域名,不進行租戶初始化,直接繼續往下執行 (使用預設資料庫)
return $next($request);
}
// 如果不是中央域名,嘗試透過域名初始化租戶
// 若找不到租戶InitializeTenancyByDomain 會拋出異常 (這正是我們要的,避免未授權訪問)
// 若找不到租戶InitializeTenancyByDomain 會拋出異常
return app(InitializeTenancyByDomain::class)->handle($request, $next);
}
}

View File

@@ -20,7 +20,7 @@ server {
location / {
proxy_pass http://star-erp-laravel:80;
proxy_set_header Host koori.star-erp.demo;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;