From f6e2e7889a1bac493b6ff9587624ca4c369dc5cc Mon Sep 17 00:00:00 2001 From: accius Date: Mon, 2 Feb 2026 22:01:19 -0500 Subject: [PATCH] Update server.js --- server.js | 103 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 63 insertions(+), 40 deletions(-) diff --git a/server.js b/server.js index 9121886..ce6d16a 100644 --- a/server.js +++ b/server.js @@ -4178,6 +4178,18 @@ app.post('/api/wsjtx/relay', (req, res) => { res.json({ ok: true, processed, timestamp: Date.now() }); }); +// API endpoint: serve raw relay.js (used by Windows .bat launcher) +app.get('/api/wsjtx/relay/agent.js', (req, res) => { + const relayJsPath = path.join(__dirname, 'wsjtx-relay', 'relay.js'); + try { + const content = fs.readFileSync(relayJsPath, 'utf8'); + res.setHeader('Content-Type', 'application/javascript'); + res.send(content); + } catch (e) { + res.status(500).json({ error: 'relay.js not found on server' }); + } +}); + // API endpoint: download pre-configured relay agent script // Embeds relay.js + server URL + relay key into a one-file launcher app.get('/api/wsjtx/relay/download/:platform', (req, res) => { @@ -4251,54 +4263,65 @@ app.get('/api/wsjtx/relay/download/:platform', (req, res) => { return res.send(script); } else if (platform === 'windows') { - // Build PowerShell script with relay.js embedded - const escapedJs = relayJs.replace(/'/g, "''"); - - const lines = [ - '# OpenHamClock WSJT-X Relay - Auto-configured', - '# Generated by ' + serverURL, - '# Right-click > "Run with PowerShell" or run from terminal', - '# Requires: Node.js 14+ (https://nodejs.org)', - '#', - '# In WSJT-X: Settings > Reporting > UDP Server', - '# Address: 127.0.0.1 Port: 2237', + // Simple .bat that downloads relay.js then runs with node + // No PowerShell, no execution policy issues + const batLines = [ + '@echo off', + 'title OpenHamClock WSJT-X Relay', + 'echo.', + 'echo =========================================', + 'echo OpenHamClock WSJT-X Relay Agent v1.0', + 'echo =========================================', + 'echo.', '', - '# Check for Node.js', - 'try {', - ' $nv = (node -v 2>$null)', - ' if (-not $nv) { throw "missing" }', - ' Write-Host "Found Node.js $nv" -ForegroundColor Green', - '} catch {', - ' Write-Host "Node.js is not installed." -ForegroundColor Red', - ' Write-Host "Download from https://nodejs.org (LTS version)" -ForegroundColor Yellow', - ' Read-Host "Press Enter to exit"', - ' exit 1', - '}', + ':: Check for Node.js', + 'where node >nul 2>nul', + 'if errorlevel 1 (', + ' echo Node.js is not installed!', + ' echo.', + ' echo Download it from: https://nodejs.org', + ' echo Install the LTS version, then run this script again.', + ' echo.', + ' pause', + ' exit /b 1', + ')', '', - '# Write relay agent to temp file', - '$relayFile = Join-Path $env:TEMP "ohc-relay.js"', + 'for /f "tokens=*" %%i in (\'node -v\') do echo Found Node.js %%i', + 'echo Server: ' + serverURL, + 'echo.', '', - "$relayCode = @'", - escapedJs, - "'@", + ':: Download relay agent', + 'echo Downloading relay agent...', + 'powershell -Command "Invoke-WebRequest -Uri \'' + serverURL + '/api/wsjtx/relay/agent.js\' -OutFile \'%TEMP%\\ohc-relay.js\'"', + 'if errorlevel 1 (', + ' echo Failed to download relay agent!', + ' echo Check your internet connection and try again.', + ' echo.', + ' pause', + ' exit /b 1', + ')', '', - '$relayCode | Out-File -FilePath $relayFile -Encoding UTF8', + 'echo Relay agent ready.', + 'echo.', + 'echo In WSJT-X: Settings ^> Reporting ^> UDP Server', + 'echo Address: 127.0.0.1 Port: 2237', + 'echo.', + 'echo Press Ctrl+C to stop', + 'echo.', '', - 'Write-Host "Starting WSJT-X relay agent..." -ForegroundColor Cyan', - 'Write-Host "Press Ctrl+C to stop" -ForegroundColor DarkGray', - 'Write-Host ""', + ':: Run relay', + 'node "%TEMP%\\ohc-relay.js" --url "' + serverURL + '" --key "' + WSJTX_RELAY_KEY + '"', '', - '# Run relay', - 'try {', - ' node $relayFile --url "' + serverURL + '" --key "' + WSJTX_RELAY_KEY + '"', - '} finally {', - ' Remove-Item $relayFile -ErrorAction SilentlyContinue', - '}', + 'echo.', + 'echo Relay stopped.', + 'del "%TEMP%\\ohc-relay.js" >nul 2>nul', + 'echo.', + 'pause', ]; - const script = lines.join('\r\n') + '\r\n'; - res.setHeader('Content-Type', 'application/x-powershell'); - res.setHeader('Content-Disposition', 'attachment; filename="start-relay.ps1"'); + const script = batLines.join('\r\n') + '\r\n'; + res.setHeader('Content-Type', 'application/x-msdos-program'); + res.setHeader('Content-Disposition', 'attachment; filename="start-relay.bat"'); return res.send(script); } else {