Compare commits
2 Commits
51e42dc538
...
87d0ff50c1
| Author | SHA1 | Date | |
|---|---|---|---|
| 87d0ff50c1 | |||
| 0499060676 |
|
|
@ -1,6 +1,7 @@
|
|||
import type { Manifest } from '@types'
|
||||
import { LOCAL_HOST } from '%config'
|
||||
|
||||
const DEFAULT_HOST = process.env.DEV ? 'http://localhost:3000' : 'http://toes.local'
|
||||
const DEFAULT_HOST = process.env.DEV ? 'http://localhost:3000' : `http://${LOCAL_HOST}`
|
||||
|
||||
const normalizeUrl = (url: string) =>
|
||||
url.startsWith('http://') || url.startsWith('https://') ? url : `http://${url}`
|
||||
|
|
|
|||
4
src/lib/config.ts
Normal file
4
src/lib/config.ts
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
import { hostname } from 'os'
|
||||
|
||||
export const HOSTNAME = hostname()
|
||||
export const LOCAL_HOST = `${HOSTNAME}.local`
|
||||
|
|
@ -4,7 +4,7 @@ import type { Subprocess } from 'bun'
|
|||
import { DEFAULT_EMOJI } from '@types'
|
||||
import { buildAppUrl, toSubdomain } from '@urls'
|
||||
import { appendFileSync, existsSync, mkdirSync, readdirSync, readFileSync, realpathSync, renameSync, symlinkSync, unlinkSync, writeFileSync } from 'fs'
|
||||
import { hostname } from 'os'
|
||||
import { LOCAL_HOST } from '%config'
|
||||
import { join, resolve } from 'path'
|
||||
import { loadAppEnv } from '../tools/env'
|
||||
import { publishApp, unpublishAll, unpublishApp } from './mdns'
|
||||
|
|
@ -16,7 +16,7 @@ export type { AppState } from '@types'
|
|||
export const APPS_DIR = process.env.APPS_DIR ?? resolve(join(process.env.DATA_DIR ?? '.', 'apps'))
|
||||
export const TOES_DIR = process.env.TOES_DIR ?? join(process.env.DATA_DIR ?? '.', 'toes')
|
||||
|
||||
const defaultHost = process.env.NODE_ENV === 'production' ? `${hostname()}.local` : 'localhost'
|
||||
const defaultHost = process.env.NODE_ENV === 'production' ? LOCAL_HOST : 'localhost'
|
||||
export const TOES_URL = process.env.TOES_URL ?? `http://${defaultHost}:${process.env.PORT || 3000}`
|
||||
|
||||
const HEALTH_CHECK_FAILURES_BEFORE_RESTART = 3
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ async function buildBinary(name: string): Promise<boolean> {
|
|||
return promise
|
||||
}
|
||||
|
||||
// Install script: curl -fsSL http://toes.local/install | bash
|
||||
// Install script: curl -fsSL http://<hostname>.local/install | bash
|
||||
app.get('/install', c => {
|
||||
if (!TOES_URL) return c.text('TOES_URL is not configured', 500)
|
||||
const script = INSTALL_SCRIPT.replace('__TOES_URL__', TOES_URL)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import type { Subprocess } from 'bun'
|
||||
import { toSubdomain } from '@urls'
|
||||
import { LOCAL_HOST } from '%config'
|
||||
import { networkInterfaces } from 'os'
|
||||
import { hostLog } from './tui'
|
||||
|
||||
|
|
@ -24,7 +25,7 @@ export function cleanupStalePublishers() {
|
|||
if (!isEnabled) return
|
||||
|
||||
try {
|
||||
const result = Bun.spawnSync(['pkill', '-f', 'avahi-publish.*toes\\.local'])
|
||||
const result = Bun.spawnSync(['pkill', '-f', `avahi-publish.*${LOCAL_HOST}`])
|
||||
if (result.exitCode === 0) {
|
||||
hostLog('mDNS: cleaned up stale avahi-publish processes')
|
||||
}
|
||||
|
|
@ -41,22 +42,22 @@ export function publishApp(name: string) {
|
|||
return
|
||||
}
|
||||
|
||||
const hostname = `${toSubdomain(name)}.toes.local`
|
||||
const host = `${toSubdomain(name)}.${LOCAL_HOST}`
|
||||
|
||||
try {
|
||||
const proc = Bun.spawn(['avahi-publish', '-a', hostname, '-R', ip], {
|
||||
const proc = Bun.spawn(['avahi-publish', '-a', host, '-R', ip], {
|
||||
stdout: 'ignore',
|
||||
stderr: 'ignore',
|
||||
})
|
||||
|
||||
_publishers.set(name, proc)
|
||||
hostLog(`mDNS: published ${hostname} -> ${ip}`)
|
||||
hostLog(`mDNS: published ${host} -> ${ip}`)
|
||||
|
||||
proc.exited.then(() => {
|
||||
_publishers.delete(name)
|
||||
})
|
||||
} catch {
|
||||
hostLog(`mDNS: failed to publish ${hostname}`)
|
||||
hostLog(`mDNS: failed to publish ${host}`)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -68,7 +69,7 @@ export function unpublishApp(name: string) {
|
|||
|
||||
proc.kill()
|
||||
_publishers.delete(name)
|
||||
hostLog(`mDNS: unpublished ${toSubdomain(name)}.toes.local`)
|
||||
hostLog(`mDNS: unpublished ${toSubdomain(name)}.${LOCAL_HOST}`)
|
||||
}
|
||||
|
||||
export function unpublishAll() {
|
||||
|
|
@ -76,7 +77,7 @@ export function unpublishAll() {
|
|||
|
||||
for (const [name, proc] of _publishers) {
|
||||
proc.kill()
|
||||
hostLog(`mDNS: unpublished ${toSubdomain(name)}.toes.local`)
|
||||
hostLog(`mDNS: unpublished ${toSubdomain(name)}.${LOCAL_HOST}`)
|
||||
}
|
||||
_publishers.clear()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user