Skip to content

Commit af6afc9

Browse files
committed
Logic adjusted to avoid locating local server
1 parent 2ef7016 commit af6afc9

3 files changed

Lines changed: 62 additions & 10 deletions

File tree

‎backend/expressServer.mjs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,11 @@ expressApp.get("/status", async (req, res) => {
921921
res.json({
922922
success: true,
923923
expressPort: serviceState.expressPort,
924+
serverIdentity: {
925+
hostName: os.hostname(),
926+
pid: process.pid,
927+
platform: process.platform
928+
},
924929
go: { running: serviceState.go.running, port: serviceState.go.port },
925930
mongo: { running: serviceState.mongo.running, port: serviceState.mongo.port },
926931
jupyter: { running: serviceState.jupyter.running, port: serviceState.jupyter.port }

‎main/background.js‎

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -608,20 +608,59 @@ ipcMain.handle('backendStatus', async (_event, { target = 'local' } = {}) => {
608608
if (target === 'remote') {
609609
const tunnel = getTunnelState()
610610
const localExpressPort = tunnel && tunnel.localExpressPort
611-
// First try: use existing local→remote forwarding to /status
612-
if (localExpressPort) {
611+
const conn = getActiveTunnel && getActiveTunnel()
612+
if (!conn) return { success: false, error: 'no-active-ssh' }
613+
614+
const normalizeHost = (value) => String(value || '').trim().toLowerCase().replace(/\.+$/, '')
615+
const shortHost = (value) => normalizeHost(value).split('.')[0]
616+
const isValidStatusPayload = (payload) => {
617+
return !!(payload && typeof payload === 'object' && payload.success === true)
618+
}
619+
620+
const remoteOS = await detectRemoteOS()
621+
const remoteHostName = await new Promise((resolve) => {
622+
try {
623+
const hostCmd = remoteOS === 'win32'
624+
? `powershell -NoProfile -Command "$env:COMPUTERNAME"`
625+
: `bash -lc "hostname -f 2>/dev/null || hostname 2>/dev/null || uname -n"`
626+
conn.exec(hostCmd, (err, stream) => {
627+
if (err) return resolve(null)
628+
let out = ''
629+
stream.on('data', (d) => { out += d.toString() })
630+
stream.stderr.on('data', () => {})
631+
stream.on('close', () => resolve((out || '').trim() || null))
632+
})
633+
} catch {
634+
resolve(null)
635+
}
636+
})
637+
638+
// First try: use existing local→remote forwarding to /status only when the express
639+
// tunnel is already known to be active, and verify identity against remote host.
640+
const tunnels = Array.isArray(tunnel?.tunnels) ? tunnel.tunnels : []
641+
const expressForward = tunnels.find((t) => t?.name === 'express')
642+
const hasActiveExpressForward = !!(
643+
localExpressPort &&
644+
expressForward &&
645+
expressForward.status === 'forwarding' &&
646+
Number(expressForward.localPort) === Number(localExpressPort)
647+
)
648+
if (hasActiveExpressForward) {
613649
try {
614650
const res = await axios.get(`http://127.0.0.1:${localExpressPort}/status`, { timeout: 3000 })
615-
if (res && res.data) return res.data
651+
const data = res && res.data
652+
const reportedHost = data && data.serverIdentity && data.serverIdentity.hostName
653+
const matchesRemoteHost = remoteHostName && reportedHost && (
654+
normalizeHost(remoteHostName) === normalizeHost(reportedHost) ||
655+
shortHost(remoteHostName) === shortHost(reportedHost)
656+
)
657+
if (isValidStatusPayload(data) && matchesRemoteHost) return data
616658
} catch {}
617659
}
618660

619-
// Fallback: sweep remote ports 5000–8000 to discover an Express server
620-
const conn = getActiveTunnel && getActiveTunnel()
621-
if (!conn) return { success: false, error: 'no-active-ssh' }
661+
// Fallback: sweep remote ports 5000-8000 to discover an Express server
622662

623663
// Single-shot list of listening ports on remote for performance
624-
const remoteOS = await detectRemoteOS()
625664
const listCmd = remoteOS === 'win32'
626665
? `netstat -an | findstr LISTEN`
627666
: `bash -c "command -v ss >/dev/null 2>&1 && ss -ltn || netstat -an | grep LISTEN"`
@@ -692,7 +731,7 @@ ipcMain.handle('backendStatus', async (_event, { target = 'local' } = {}) => {
692731

693732
for (const rp of ports) {
694733
const found = await tryPortStatus(rp)
695-
if (found && found.data) {
734+
if (found && isValidStatusPayload(found.data)) {
696735
// Persistently start Express forward using discovered remote port
697736
try {
698737
await startExpressForward({ remoteExpressPort: rp })

‎renderer/components/mainPages/connectionModal.jsx‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,7 @@ const ConnectionModal = ({ visible, closable, onClose, onConnect }) =>{
921921
if (!withinGrace) setRemoteServerRunning(false)
922922
setShouldRecheck(true)
923923
} else {
924-
setRemoteBackendStatus('Remote server not found. Install or locate it.')
924+
setRemoteBackendStatus('Remote server not found. Please install it first.')
925925
setRemoteServerRunning(false)
926926
setShouldRecheck(false)
927927
}
@@ -1679,6 +1679,7 @@ const ConnectionModal = ({ visible, closable, onClose, onConnect }) =>{
16791679
]
16801680

16811681
const serverSetupActionsBusy = checkingRemoteServerBusy || installingRemote || startingRemoteServerBusy || checkingRemotePortBusy
1682+
const startServerButtonDisabled = !tunnelActive || connectionProcessing || serverSetupActionsBusy || !remoteInstalled
16821683

16831684
const formatReleaseTagForDisplay = (tag) => {
16841685
const cleaned = String(tag || '').trim().replace(/^server[-_]?/i, '')
@@ -1958,7 +1959,14 @@ const ConnectionModal = ({ visible, closable, onClose, onConnect }) =>{
19581959
<span>Start on port:</span>
19591960
<InputNumber disabled={!tunnelActive || connectionProcessing || serverSetupActionsBusy} value={remoteStartPort} onChange={e => setRemoteStartPort(e.value)} useGrouping={false} min={1} max={65535} />
19601961
{!remoteServerRunning ? (
1961-
<Button onClick={startRemoteServer} disabled={!tunnelActive || connectionProcessing || serverSetupActionsBusy} style={{ background: 'var(--button-bg)', color: 'var(--button-text)' }}>Start Server</Button>
1962+
<Button
1963+
onClick={startRemoteServer}
1964+
disabled={startServerButtonDisabled}
1965+
title={!remoteInstalled ? 'Please install the remote server first.' : 'Start remote server'}
1966+
style={{ background: 'var(--button-bg)', color: 'var(--button-text)' }}
1967+
>
1968+
Start Server
1969+
</Button>
19621970
) : (
19631971
<Button onClick={stopRemoteServer} disabled={!tunnelActive || connectionProcessing || serverSetupActionsBusy} style={{ background: 'var(--danger)', color: 'var(--button-text)' }}>Stop Server</Button>
19641972
)}

0 commit comments

Comments
 (0)