Add SERVER_PORT export and fix tunnel port selection

This commit is contained in:
Chris Wanstrath 2026-05-11 14:52:44 -07:00
parent 875c89de18
commit 3743a01c28
2 changed files with 9 additions and 3 deletions

View File

@ -1,4 +1,4 @@
import { APPS_DIR, TOES_DIR, TOES_URL, allApps, appendLog, getLogDates, onChange, readLogs, registerApp, renameApp, restartApp, startApp, stopApp, updateAppIcon } from '$apps'
import { APPS_DIR, SERVER_PORT, TOES_DIR, TOES_URL, allApps, appendLog, getLogDates, onChange, readLogs, registerApp, renameApp, restartApp, startApp, stopApp, updateAppIcon } from '$apps'
import { buildAppUrl } from '@urls'
import { isTunnelsAvailable, shareApp, unshareApp } from '../tunnels'
import type { App as BackendApp } from '$apps'
@ -407,7 +407,7 @@ router.post('/:app/tunnel', c => {
if (app.state !== 'running') return c.json({ ok: false, error: 'App must be running to enable tunnel' }, 400)
shareApp(appName, app.port ?? 0)
shareApp(appName, app.static ? SERVER_PORT : (app.port ?? 0))
return c.json({ ok: true })
})

View File

@ -18,10 +18,12 @@ export const TOES_DIR = process.env.TOES_DIR ?? join(process.env.DATA_DIR ?? '.'
const dataRoot = process.env.DATA_DIR ?? '.'
export const SERVER_PORT = Number(process.env.PORT || 3000)
const defaultHost = process.env.NODE_ENV === 'production' ? LOCAL_HOST : 'localhost'
export const TOES_URL = process.env.TOES_URL ?? (process.env.NODE_ENV === 'production'
? `http://${defaultHost}`
: `http://${defaultHost}:${process.env.PORT || 3000}`)
: `http://${defaultHost}:${SERVER_PORT}`)
const HEALTH_CHECK_FAILURES_BEFORE_RESTART = 3
const HEALTH_CHECK_INTERVAL = 30000
@ -170,6 +172,7 @@ export function registerApp(dir: string) {
runApp(dir, getPort(dir))
} else if (isStatic) {
publishApp(dir)
openTunnelIfEnabled(dir, SERVER_PORT)
}
}
@ -241,6 +244,7 @@ export function startApp(dir: string) {
update()
emit({ type: 'app:start', app: dir })
publishApp(dir)
openTunnelIfEnabled(dir, SERVER_PORT)
return
}
@ -298,6 +302,7 @@ export function stopApp(dir: string) {
app.started = undefined
app.manuallyStopped = true
unpublishApp(dir)
closeTunnel(dir)
update()
emit({ type: 'app:stop', app: dir })
return
@ -398,6 +403,7 @@ function discoverApps() {
if (isStatic) {
app.started = Date.now()
publishApp(dir)
openTunnelIfEnabled(dir, SERVER_PORT)
}
_apps.set(dir, app)
}