fix: use correct server URL instead of localhost #47

Merged
rafaga21 merged 2 commits from feat/push-monitoring-agent-v2 into master 2026-06-11 20:29:40 -04:00
Showing only changes of commit 26e35c6bc7 - Show all commits

View File

@@ -37,13 +37,12 @@ class AgentService
$agentKey = $server['agent_key'];
$serverUrl = rtrim((App::getConfig()['app']['url'] ?? ''), '/');
if (empty($serverUrl) || str_contains($serverUrl, 'localhost')) {
$serverUrl = ($_SERVER['HTTPS'] ?? '' === 'on' ? 'https://' : 'http://') . ($_SERVER['HTTP_HOST'] ?? 'sysadmin.lan');
if (empty($serverUrl)) {
$scheme = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https://' : 'http://';
$host = $_SERVER['HTTP_HOST'] ?? 'localhost';
$serverUrl = $scheme . $host;
}
// Replace localhost with actual hostname if still localhost
$serverUrl = preg_replace('/https?:\/\/localhost(:\d+)?/', 'http://sysadmin.lan$1', $serverUrl);
$scriptPath = $this->basePath . '/install/agent-install.sh';
if (!file_exists($scriptPath)) {