1.修复自动创建下一期bug

This commit is contained in:
2026-05-26 18:30:19 +08:00
parent bdd66f7bd9
commit bb5ef82d49
7 changed files with 169 additions and 69 deletions

View File

@@ -11,6 +11,9 @@ final class WebSocketConfigHelper
public static function wsUrl(?Request $request = null): string
{
$url = trim((string) env('H5_WEBSOCKET_URL', ''));
if ($url !== '' && $request !== null && self::isLoopbackWsUrl($url) && !self::isLoopbackRequestHost($request)) {
$url = '';
}
if ($url !== '') {
return $url;
}
@@ -36,5 +39,30 @@ final class WebSocketConfigHelper
return 'ws://127.0.0.1:3131/ws/';
}
private static function isLoopbackWsUrl(string $url): bool
{
$host = parse_url($url, PHP_URL_HOST);
if (!is_string($host) || $host === '') {
return false;
}
$host = strtolower($host);
return in_array($host, ['127.0.0.1', 'localhost', '::1'], true);
}
private static function isLoopbackRequestHost(Request $request): bool
{
$host = strtolower(trim((string) $request->host(true)));
if ($host === '') {
$host = strtolower(trim((string) $request->header('host', '')));
}
if ($host === '') {
return false;
}
$hostOnly = preg_split('/:/', $host)[0] ?? $host;
return in_array($hostOnly, ['127.0.0.1', 'localhost', '::1'], true);
}
}