Centralize hostname config in shared module
This commit is contained in:
parent
0499060676
commit
87d0ff50c1
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
# It isn't enough to modify this yet.
|
||||
# You also need to manually update the toes.service file.
|
||||
HOST="${HOST:-toes@$(hostname).local}"
|
||||
URL="${URL:-http://$(hostname).local}"
|
||||
HOST="${HOST:-toes@toes.local}"
|
||||
URL="${URL:-http://toes.local}"
|
||||
DEST="${DEST:-~/toes}"
|
||||
DATA_DIR="${DATA_DIR:-~/data}"
|
||||
APPS_DIR="${APPS_DIR:-~/apps}"
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import type { Manifest } from '@types'
|
||||
import { hostname } from 'os'
|
||||
import { LOCAL_HOST } from '%config'
|
||||
|
||||
const DEFAULT_HOST = process.env.DEV ? 'http://localhost:3000' : `http://${hostname()}.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
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import type { Subprocess } from 'bun'
|
||||
import { toSubdomain } from '@urls'
|
||||
import { hostname, networkInterfaces } from 'os'
|
||||
import { LOCAL_HOST } from '%config'
|
||||
import { networkInterfaces } from 'os'
|
||||
import { hostLog } from './tui'
|
||||
|
||||
const _publishers = new Map<string, Subprocess>()
|
||||
|
|
@ -24,7 +25,7 @@ export function cleanupStalePublishers() {
|
|||
if (!isEnabled) return
|
||||
|
||||
try {
|
||||
const result = Bun.spawnSync(['pkill', '-f', `avahi-publish.*${hostname()}\\.local`])
|
||||
const result = Bun.spawnSync(['pkill', '-f', `avahi-publish.*${LOCAL_HOST}`])
|
||||
if (result.exitCode === 0) {
|
||||
hostLog('mDNS: cleaned up stale avahi-publish processes')
|
||||
}
|
||||
|
|
@ -41,7 +42,7 @@ export function publishApp(name: string) {
|
|||
return
|
||||
}
|
||||
|
||||
const host = `${toSubdomain(name)}.${hostname()}.local`
|
||||
const host = `${toSubdomain(name)}.${LOCAL_HOST}`
|
||||
|
||||
try {
|
||||
const proc = Bun.spawn(['avahi-publish', '-a', host, '-R', ip], {
|
||||
|
|
@ -68,7 +69,7 @@ export function unpublishApp(name: string) {
|
|||
|
||||
proc.kill()
|
||||
_publishers.delete(name)
|
||||
hostLog(`mDNS: unpublished ${toSubdomain(name)}.${hostname()}.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)}.${hostname()}.local`)
|
||||
hostLog(`mDNS: unpublished ${toSubdomain(name)}.${LOCAL_HOST}`)
|
||||
}
|
||||
_publishers.clear()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user