mirror of
https://github.com/pockethost/pockethost.git
synced 2025-06-07 14:46:41 +00:00
enh(multi): Add public instance URL calculators and refactor HTTP protocol detection
This commit is contained in:
parent
12f029a294
commit
b7277cf885
6
.changeset/1719706211493.md
Normal file
6
.changeset/1719706211493.md
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
'@pockethost/plugin-launcher-spawn': minor
|
||||||
|
'pockethost': minor
|
||||||
|
---
|
||||||
|
|
||||||
|
Add public instance URL calculators and refactor HTTP protocol detection
|
@ -21,10 +21,9 @@ import {
|
|||||||
} from 'pockethost'
|
} from 'pockethost'
|
||||||
import {
|
import {
|
||||||
APEX_DOMAIN,
|
APEX_DOMAIN,
|
||||||
INSTANCE_DATA_DIR,
|
HTTP_PROTOCOL,
|
||||||
PORT,
|
PORT,
|
||||||
exitHook,
|
PUBLIC_INSTANCE_URL,
|
||||||
tryFetch,
|
|
||||||
} from 'pockethost/core'
|
} from 'pockethost/core'
|
||||||
import { PLUGIN_NAME, settings } from './constants'
|
import { PLUGIN_NAME, settings } from './constants'
|
||||||
import { DbService } from './db'
|
import { DbService } from './db'
|
||||||
@ -92,15 +91,14 @@ export const plugin: PocketHostPlugin = async ({}) => {
|
|||||||
|
|
||||||
/** Display some informational alerts to help the user get started. */
|
/** Display some informational alerts to help the user get started. */
|
||||||
onAfterServerStartAction(async () => {
|
onAfterServerStartAction(async () => {
|
||||||
const protocol = PORT() === 443 ? 'https' : 'http'
|
const protocol = HTTP_PROTOCOL()
|
||||||
{
|
{
|
||||||
const url = new URL(`${protocol}://*.${APEX_DOMAIN()}`)
|
const url = new URL(`${protocol}//*.${APEX_DOMAIN()}`)
|
||||||
url.port = `${PORT() === 80 || PORT() == 443 ? '' : PORT()}`
|
url.port = `${PORT() === 80 || PORT() == 443 ? '' : PORT()}`
|
||||||
info(`Listening for requests on ${url}`)
|
info(`Listening for requests on ${url}`)
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
const url = new URL(`${protocol}://hello.${APEX_DOMAIN()}`)
|
const url = PUBLIC_INSTANCE_URL({ subdomain: 'hello' })
|
||||||
url.port = `${PORT() === 80 || PORT() == 443 ? '' : PORT()}`
|
|
||||||
info(`Try visiting ${url}`)
|
info(`Try visiting ${url}`)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -57,7 +57,9 @@ export const DATA_DIR = (...paths: string[]) =>
|
|||||||
export const NODE_ENV = () => process.env.NODE_ENV
|
export const NODE_ENV = () => process.env.NODE_ENV
|
||||||
export const INSTANCE_DATA_DIR = (id: InstanceId, ...paths: string[]) =>
|
export const INSTANCE_DATA_DIR = (id: InstanceId, ...paths: string[]) =>
|
||||||
join(DATA_DIR(), id, ...paths)
|
join(DATA_DIR(), id, ...paths)
|
||||||
|
export const HTTP_PROTOCOL = () => (PORT() === 443 ? 'https:' : 'http:')
|
||||||
if (DEBUG()) {
|
export const PUBLIC_INSTANCE_URL = ({ subdomain }: Partial<InstanceFields>) => {
|
||||||
logSettings(settings)
|
const url = new URL(`${HTTP_PROTOCOL()}//${subdomain}.${APEX_DOMAIN()}`)
|
||||||
|
url.port = `${PORT() === 80 || PORT() == 443 ? '' : PORT()}`
|
||||||
|
return url
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user