Add SERVER_PORT export and fix tunnel port selection
This commit is contained in:
parent
875c89de18
commit
3743a01c28
|
|
@ -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 { buildAppUrl } from '@urls'
|
||||||
import { isTunnelsAvailable, shareApp, unshareApp } from '../tunnels'
|
import { isTunnelsAvailable, shareApp, unshareApp } from '../tunnels'
|
||||||
import type { App as BackendApp } from '$apps'
|
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)
|
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 })
|
return c.json({ ok: true })
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,10 +18,12 @@ export const TOES_DIR = process.env.TOES_DIR ?? join(process.env.DATA_DIR ?? '.'
|
||||||
|
|
||||||
const dataRoot = 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'
|
const defaultHost = process.env.NODE_ENV === 'production' ? LOCAL_HOST : 'localhost'
|
||||||
export const TOES_URL = process.env.TOES_URL ?? (process.env.NODE_ENV === 'production'
|
export const TOES_URL = process.env.TOES_URL ?? (process.env.NODE_ENV === 'production'
|
||||||
? `http://${defaultHost}`
|
? `http://${defaultHost}`
|
||||||
: `http://${defaultHost}:${process.env.PORT || 3000}`)
|
: `http://${defaultHost}:${SERVER_PORT}`)
|
||||||
|
|
||||||
const HEALTH_CHECK_FAILURES_BEFORE_RESTART = 3
|
const HEALTH_CHECK_FAILURES_BEFORE_RESTART = 3
|
||||||
const HEALTH_CHECK_INTERVAL = 30000
|
const HEALTH_CHECK_INTERVAL = 30000
|
||||||
|
|
@ -170,6 +172,7 @@ export function registerApp(dir: string) {
|
||||||
runApp(dir, getPort(dir))
|
runApp(dir, getPort(dir))
|
||||||
} else if (isStatic) {
|
} else if (isStatic) {
|
||||||
publishApp(dir)
|
publishApp(dir)
|
||||||
|
openTunnelIfEnabled(dir, SERVER_PORT)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -241,6 +244,7 @@ export function startApp(dir: string) {
|
||||||
update()
|
update()
|
||||||
emit({ type: 'app:start', app: dir })
|
emit({ type: 'app:start', app: dir })
|
||||||
publishApp(dir)
|
publishApp(dir)
|
||||||
|
openTunnelIfEnabled(dir, SERVER_PORT)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -298,6 +302,7 @@ export function stopApp(dir: string) {
|
||||||
app.started = undefined
|
app.started = undefined
|
||||||
app.manuallyStopped = true
|
app.manuallyStopped = true
|
||||||
unpublishApp(dir)
|
unpublishApp(dir)
|
||||||
|
closeTunnel(dir)
|
||||||
update()
|
update()
|
||||||
emit({ type: 'app:stop', app: dir })
|
emit({ type: 'app:stop', app: dir })
|
||||||
return
|
return
|
||||||
|
|
@ -398,6 +403,7 @@ function discoverApps() {
|
||||||
if (isStatic) {
|
if (isStatic) {
|
||||||
app.started = Date.now()
|
app.started = Date.now()
|
||||||
publishApp(dir)
|
publishApp(dir)
|
||||||
|
openTunnelIfEnabled(dir, SERVER_PORT)
|
||||||
}
|
}
|
||||||
_apps.set(dir, app)
|
_apps.set(dir, app)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user