fix some bugs
This commit is contained in:
@@ -803,7 +803,8 @@ class ConfigService
|
||||
|
||||
/**
|
||||
* Hostname for WebOTP SMS (@domain #code) and other public links.
|
||||
* Only from the current HTTP request — no settings, no .env.
|
||||
* Prefer settings.app_url (دامنهٔ اپ کاربر) over the API request host —
|
||||
* API often lives on a different subdomain (e.g. *.gholaktala.ir).
|
||||
*/
|
||||
public function resolvePublicHost(?\Illuminate\Http\Request $request = null): string
|
||||
{
|
||||
@@ -816,9 +817,14 @@ class ConfigService
|
||||
return '';
|
||||
}
|
||||
|
||||
/** Full user-facing site URL, e.g. https://example.ir */
|
||||
/** Full user-facing site URL, e.g. https://example.ir — prefers settings.app_url */
|
||||
public function resolvePublicSiteUrl(?\Illuminate\Http\Request $request = null): string
|
||||
{
|
||||
$fromAppUrl = $this->normalizedAppUrl();
|
||||
if ($fromAppUrl !== '') {
|
||||
return $fromAppUrl;
|
||||
}
|
||||
|
||||
if ($request !== null) {
|
||||
$origin = rtrim(trim((string) $request->getSchemeAndHttpHost()), '/');
|
||||
$host = $this->parseHostFromUrl($origin);
|
||||
@@ -854,6 +860,11 @@ class ConfigService
|
||||
{
|
||||
$candidates = [];
|
||||
|
||||
$appUrlHost = $this->parseHostFromUrl((string) $this->get('app_url', ''));
|
||||
if ($appUrlHost !== '') {
|
||||
$candidates[] = $appUrlHost;
|
||||
}
|
||||
|
||||
if ($request !== null) {
|
||||
$candidates[] = trim((string) $request->getHost());
|
||||
}
|
||||
@@ -865,6 +876,33 @@ class ConfigService
|
||||
return $candidates;
|
||||
}
|
||||
|
||||
/** settings.app_url as https://host… without trailing slash; empty if unusable */
|
||||
private function normalizedAppUrl(): string
|
||||
{
|
||||
$raw = trim((string) $this->get('app_url', ''));
|
||||
if ($raw === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (! preg_match('#^https?://#i', $raw)) {
|
||||
$raw = 'https://' . ltrim($raw, '/');
|
||||
}
|
||||
|
||||
$host = $this->parseHostFromUrl($raw);
|
||||
if (! $this->isUsableHost($host)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$scheme = parse_url($raw, PHP_URL_SCHEME) ?: 'https';
|
||||
$port = parse_url($raw, PHP_URL_PORT);
|
||||
$origin = strtolower((string) $scheme) . '://' . $this->normalizeHost($host);
|
||||
if ($port !== null && ! in_array((int) $port, [80, 443], true)) {
|
||||
$origin .= ':' . $port;
|
||||
}
|
||||
|
||||
return $origin;
|
||||
}
|
||||
|
||||
private function isUsableHost(string $host): bool
|
||||
{
|
||||
$host = strtolower(trim($host));
|
||||
|
||||
Reference in New Issue
Block a user