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