mirror of
https://github.com/pockethost/pockethost.git
synced 2025-03-30 15:08:30 +00:00
refactor: constants and helpers
This commit is contained in:
parent
a6ad194827
commit
1b749a621b
@ -10,11 +10,12 @@ dotenv.config({ path: `../../.env` })
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export const PUBLIC_HTTP_PROTOCOL = env('PUBLIC_HTTP_PROTOCOL', 'https')
|
export const PUBLIC_HTTP_PROTOCOL = env('PUBLIC_HTTP_PROTOCOL', 'https')
|
||||||
export const PUBLIC_APP_DOMAIN = env('PUBLIC_APP_DOMAIN', `app.pockethost.io`)
|
export const PUBLIC_APP_SUBDOMAIN = env('PUBLIC_APP_SUBDOMAIN', `app`)
|
||||||
export const PUBLIC_BLOG_DOMAIN = env('PUBLIC_BLOG_DOMAIN', `pockethost.io`)
|
export const PUBLIC_BLOG_SUBDOMAIN = env('PUBLIC_BLOG_DOMAIN', ``)
|
||||||
|
export const PUBLIC_APEX_DOMAIN = env('PUBLIC_APEX_DOMAIN', `pockethost.lvh.me`)
|
||||||
export const PUBLIC_EDGE_APEX_DOMAIN = env(
|
export const PUBLIC_EDGE_APEX_DOMAIN = env(
|
||||||
'PUBLIC_EDGE_APEX_DOMAIN',
|
'PUBLIC_EDGE_APEX_DOMAIN',
|
||||||
`pockethost.io`,
|
`pockethost.lvh.me`,
|
||||||
)
|
)
|
||||||
export const PUBLIC_MOTHERSHIP_NAME = env(
|
export const PUBLIC_MOTHERSHIP_NAME = env(
|
||||||
'PUBLIC_MOTHERSHIP_NAME',
|
'PUBLIC_MOTHERSHIP_NAME',
|
||||||
@ -22,6 +23,18 @@ export const PUBLIC_MOTHERSHIP_NAME = env(
|
|||||||
)
|
)
|
||||||
export const PUBLIC_DEBUG = envb('PUBLIC_DEBUG', false)
|
export const PUBLIC_DEBUG = envb('PUBLIC_DEBUG', false)
|
||||||
|
|
||||||
|
export const mkFqDomain = (subdomain: string) =>
|
||||||
|
`${subdomain ? `${subdomain}.` : ''}${PUBLIC_APEX_DOMAIN}`
|
||||||
|
export const mkUrl = (subdomain: string, path = '') =>
|
||||||
|
`${PUBLIC_HTTP_PROTOCOL}://${mkFqDomain(subdomain)}${path}`
|
||||||
|
export const mkAppUrl = (path = '') => mkUrl(PUBLIC_APP_SUBDOMAIN, path)
|
||||||
|
export const mkBlogUrl = (path = '') => mkUrl(PUBLIC_BLOG_SUBDOMAIN, path)
|
||||||
|
export const mkDocUrl = (path = '') => mkBlogUrl(join('docs', path))
|
||||||
|
export const mkEdgeSubdomain = (subdomain: string) =>
|
||||||
|
mkFqDomain(`${subdomain}.${PUBLIC_EDGE_APEX_DOMAIN}`)
|
||||||
|
export const mkEdgeUrl = (subdomain: string, path = '') =>
|
||||||
|
mkUrl(mkEdgeSubdomain(subdomain), path)
|
||||||
|
|
||||||
// Derived
|
// Derived
|
||||||
export const MOTHERSHIP_URL = `${PUBLIC_HTTP_PROTOCOL}://${PUBLIC_MOTHERSHIP_NAME}.${PUBLIC_EDGE_APEX_DOMAIN}`
|
export const MOTHERSHIP_URL = `${PUBLIC_HTTP_PROTOCOL}://${PUBLIC_MOTHERSHIP_NAME}.${PUBLIC_EDGE_APEX_DOMAIN}`
|
||||||
|
|
||||||
@ -73,9 +86,9 @@ export const DOCKER_ARCH = env('DOCKER_ARCH', 'arm64')
|
|||||||
|
|
||||||
console.log({
|
console.log({
|
||||||
PUBLIC_HTTP_PROTOCOL,
|
PUBLIC_HTTP_PROTOCOL,
|
||||||
PUBLIC_APP_DOMAIN,
|
PUBLIC_APP_SUBDOMAIN,
|
||||||
PUBLIC_MOTHERSHIP_NAME,
|
PUBLIC_MOTHERSHIP_NAME,
|
||||||
PUBLIC_BLOG_DOMAIN,
|
PUBLIC_BLOG_SUBDOMAIN,
|
||||||
PUBLIC_DEBUG,
|
PUBLIC_DEBUG,
|
||||||
PUBLIC_EDGE_APEX_DOMAIN,
|
PUBLIC_EDGE_APEX_DOMAIN,
|
||||||
DAEMON_PB_USERNAME,
|
DAEMON_PB_USERNAME,
|
||||||
|
@ -1,24 +1,24 @@
|
|||||||
import {
|
import {
|
||||||
DAEMON_PB_IDLE_TTL,
|
DAEMON_PB_IDLE_TTL,
|
||||||
PUBLIC_APP_DOMAIN,
|
mkAppUrl,
|
||||||
PUBLIC_HTTP_PROTOCOL,
|
mkDocUrl,
|
||||||
PUBLIC_MOTHERSHIP_NAME,
|
PUBLIC_MOTHERSHIP_NAME,
|
||||||
} from '$constants'
|
} from '$constants'
|
||||||
import { clientService, proxyService } from '$services'
|
import { clientService, proxyService } from '$services'
|
||||||
import { mkInternalUrl, now } from '$util'
|
import { mkInternalUrl, now } from '$util'
|
||||||
import {
|
import {
|
||||||
|
assertTruthy,
|
||||||
CLEANUP_PRIORITY_LAST,
|
CLEANUP_PRIORITY_LAST,
|
||||||
|
createCleanupManager,
|
||||||
|
createTimerManager,
|
||||||
InstanceFields,
|
InstanceFields,
|
||||||
InstanceId,
|
InstanceId,
|
||||||
InstanceStatus,
|
InstanceStatus,
|
||||||
SingletonBaseConfig,
|
|
||||||
StreamNames,
|
|
||||||
assertTruthy,
|
|
||||||
createCleanupManager,
|
|
||||||
createTimerManager,
|
|
||||||
mkSingleton,
|
mkSingleton,
|
||||||
safeCatch,
|
safeCatch,
|
||||||
serialAsyncExecutionGuard,
|
serialAsyncExecutionGuard,
|
||||||
|
SingletonBaseConfig,
|
||||||
|
StreamNames,
|
||||||
} from '@pockethost/common'
|
} from '@pockethost/common'
|
||||||
import { map, values } from '@s-libs/micro-dash'
|
import { map, values } from '@s-libs/micro-dash'
|
||||||
import Bottleneck from 'bottleneck'
|
import Bottleneck from 'bottleneck'
|
||||||
@ -468,7 +468,9 @@ export const instanceService = mkSingleton(
|
|||||||
dbg(`Checking for maintenance mode`)
|
dbg(`Checking for maintenance mode`)
|
||||||
if (instance.maintenance) {
|
if (instance.maintenance) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`This instance is in Maintenance Mode. See https://pockethost.io/docs/usage/maintenance for more information.`,
|
`This instance is in Maintenance Mode. See ${mkDocUrl(
|
||||||
|
`/usage/maintenance`,
|
||||||
|
)} for more information.`,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -477,9 +479,7 @@ export const instanceService = mkSingleton(
|
|||||||
*/
|
*/
|
||||||
dbg(`Checking for verified account`)
|
dbg(`Checking for verified account`)
|
||||||
if (!owner?.verified) {
|
if (!owner?.verified) {
|
||||||
throw new Error(
|
throw new Error(`Log in at ${mkAppUrl()}} to verify your account.`)
|
||||||
`Log in at ${PUBLIC_HTTP_PROTOCOL}://${PUBLIC_APP_DOMAIN} to verify your account.`,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const api = await getInstanceApi(instance)
|
const api = await getInstanceApi(instance)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user