From a1dfee22a7ea4328d68852bedea2ea73c9089311 Mon Sep 17 00:00:00 2001 From: Ben Allfree Date: Wed, 31 Jul 2024 02:53:23 -0400 Subject: [PATCH] chore(pockethost): refactor MOTHERSHIP_URL --- .../DaemonCommand/ServeCommand/daemon.ts | 8 ++++---- .../EdgeCommand/FtpCommand/FtpService/index.ts | 4 ++-- .../EdgeCommand/FtpCommand/ServeCommand/ftp.ts | 6 +++--- .../cli/commands/SendMailCommand/sendmail.ts | 3 +-- packages/pockethost/src/constants.ts | 18 +++++++++--------- 5 files changed, 19 insertions(+), 20 deletions(-) diff --git a/packages/pockethost/src/cli/commands/EdgeCommand/DaemonCommand/ServeCommand/daemon.ts b/packages/pockethost/src/cli/commands/EdgeCommand/DaemonCommand/ServeCommand/daemon.ts index 7ebe8b3c..e1a59f0b 100644 --- a/packages/pockethost/src/cli/commands/EdgeCommand/DaemonCommand/ServeCommand/daemon.ts +++ b/packages/pockethost/src/cli/commands/EdgeCommand/DaemonCommand/ServeCommand/daemon.ts @@ -3,7 +3,7 @@ import { LoggerService } from '../../../../../common' import { MOTHERSHIP_ADMIN_PASSWORD, MOTHERSHIP_ADMIN_USERNAME, - MOTHERSHIP_INTERNAL_URL, + MOTHERSHIP_URL, discordAlert, tryFetch, } from '../../../../../core' @@ -24,19 +24,19 @@ export async function daemon() { await PortService({}) await PocketbaseService({}) - await tryFetch(`${MOTHERSHIP_INTERNAL_URL(`/api/health`)}`, {}) + await tryFetch(`${MOTHERSHIP_URL(`/api/health`)}`, {}) info(`Serving`) /** Launch services */ await MothershipAdminClientService({ - url: MOTHERSHIP_INTERNAL_URL(), + url: MOTHERSHIP_URL(), username: MOTHERSHIP_ADMIN_USERNAME(), password: MOTHERSHIP_ADMIN_PASSWORD(), }) await proxyService({ - coreInternalUrl: MOTHERSHIP_INTERNAL_URL(), + coreInternalUrl: MOTHERSHIP_URL(), }) await realtimeLog({}) await instanceService({ diff --git a/packages/pockethost/src/cli/commands/EdgeCommand/FtpCommand/FtpService/index.ts b/packages/pockethost/src/cli/commands/EdgeCommand/FtpCommand/FtpService/index.ts index 4dfca964..9e196db4 100644 --- a/packages/pockethost/src/cli/commands/EdgeCommand/FtpCommand/FtpService/index.ts +++ b/packages/pockethost/src/cli/commands/EdgeCommand/FtpCommand/FtpService/index.ts @@ -8,7 +8,7 @@ import { mkSingleton, } from '../../../../../common' import { - MOTHERSHIP_INTERNAL_URL, + MOTHERSHIP_URL, PH_FTP_PASV_IP, PH_FTP_PASV_PORT_MAX, PH_FTP_PASV_PORT_MIN, @@ -67,7 +67,7 @@ export function virtualFolderGuard( export const ftpService = mkSingleton((config: Partial = {}) => { const { mothershipUrl } = mergeConfig( { - mothershipUrl: MOTHERSHIP_INTERNAL_URL(), + mothershipUrl: MOTHERSHIP_URL(), }, config, ) diff --git a/packages/pockethost/src/cli/commands/EdgeCommand/FtpCommand/ServeCommand/ftp.ts b/packages/pockethost/src/cli/commands/EdgeCommand/FtpCommand/ServeCommand/ftp.ts index 9bc1720a..16279331 100644 --- a/packages/pockethost/src/cli/commands/EdgeCommand/FtpCommand/ServeCommand/ftp.ts +++ b/packages/pockethost/src/cli/commands/EdgeCommand/FtpCommand/ServeCommand/ftp.ts @@ -1,5 +1,5 @@ import { LoggerService } from '../../../../../common' -import { MOTHERSHIP_INTERNAL_URL, tryFetch } from '../../../../../core' +import { MOTHERSHIP_URL, tryFetch } from '../../../../../core' import { ftpService } from '../FtpService' export async function ftp() { @@ -7,9 +7,9 @@ export async function ftp() { const { dbg, error, info, warn } = logger info(`Starting`) - await tryFetch(`${MOTHERSHIP_INTERNAL_URL(`/api/health`)}`, {}) + await tryFetch(`${MOTHERSHIP_URL(`/api/health`)}`, {}) await ftpService({ - mothershipUrl: MOTHERSHIP_INTERNAL_URL(), + mothershipUrl: MOTHERSHIP_URL(), }) } diff --git a/packages/pockethost/src/cli/commands/SendMailCommand/sendmail.ts b/packages/pockethost/src/cli/commands/SendMailCommand/sendmail.ts index 5914f5b1..1cbda169 100644 --- a/packages/pockethost/src/cli/commands/SendMailCommand/sendmail.ts +++ b/packages/pockethost/src/cli/commands/SendMailCommand/sendmail.ts @@ -6,7 +6,6 @@ import { MOTHERSHIP_ADMIN_PASSWORD, MOTHERSHIP_ADMIN_USERNAME, MOTHERSHIP_DATA_DB, - MOTHERSHIP_INTERNAL_URL, MOTHERSHIP_URL, TEST_EMAIL, } from '../../../core' @@ -51,7 +50,7 @@ export const sendMail = async () => { info(MOTHERSHIP_URL()) - const client = new PocketBase(MOTHERSHIP_INTERNAL_URL()) + const client = new PocketBase(MOTHERSHIP_URL()) await client.admins.authWithPassword( MOTHERSHIP_ADMIN_USERNAME(), MOTHERSHIP_ADMIN_PASSWORD(), diff --git a/packages/pockethost/src/constants.ts b/packages/pockethost/src/constants.ts index a7f4a8b2..b6fa0661 100644 --- a/packages/pockethost/src/constants.ts +++ b/packages/pockethost/src/constants.ts @@ -98,11 +98,7 @@ export const SETTINGS = { DAEMON_PORT: mkNumber(3000), DAEMON_PB_IDLE_TTL: mkNumber(1000 * 60 * 5), // 5 minutes - MOTHERSHIP_URL: mkString( - `${_HTTP_PROTOCOL}//${_MOTHERSHIP_NAME}.${_APEX_DOMAIN}`, - ), MOTHERSHIP_NAME: mkString(_MOTHERSHIP_NAME), - MOTHERSHIP_INTERNAL_HOST: mkString(`localhost`), MOTHERSHIP_ADMIN_USERNAME: mkString(), MOTHERSHIP_ADMIN_PASSWORD: mkString(), PH_MOTHERSHIP_APP_ROOT: mkString(_MOTHERSHIP_APP_ROOT()), @@ -224,9 +220,15 @@ export const IPCIDR_LIST = () => settings().IPCIDR_LIST export const DAEMON_PORT = () => settings().DAEMON_PORT export const DAEMON_PB_IDLE_TTL = () => settings().DAEMON_PB_IDLE_TTL -export const MOTHERSHIP_URL = () => settings().MOTHERSHIP_URL -export const MOTHERSHIP_INTERNAL_HOST = () => - settings().MOTHERSHIP_INTERNAL_HOST +export const MOTHERSHIP_URL = (...path: string[]) => + join( + env + .get('MOTHERSHIP_URL') + .default(`${HTTP_PROTOCOL()}://${MOTHERSHIP_NAME()}:${APEX_DOMAIN()}`) + .asString(), + ...path, + ) + export const MOTHERSHIP_NAME = () => settings().MOTHERSHIP_NAME export const MOTHERSHIP_ADMIN_USERNAME = () => settings().MOTHERSHIP_ADMIN_USERNAME @@ -286,8 +288,6 @@ export const MOTHERSHIP_DATA_ROOT = (...paths: string[]) => join(INSTANCE_DATA_ROOT(MOTHERSHIP_NAME()), ...paths) export const MOTHERSHIP_DATA_DB = () => join(MOTHERSHIP_DATA_ROOT(), `pb_data`, `data.db`) -export const MOTHERSHIP_INTERNAL_URL = (path = '') => - `http://${MOTHERSHIP_INTERNAL_HOST()}:${MOTHERSHIP_PORT()}${path}` export const INSTANCE_DATA_ROOT = (id: InstanceId) => join(DATA_ROOT(), id) export const INSTANCE_DATA_DB = (id: InstanceId) => join(DATA_ROOT(), id, `pb_data`, `data.db`)