← Public packages
@noah/mega-radio
MEGA Radio (the WAKE album) for members of the MEGA.dev Discord: sign in with Kody, verify with Discord, listen with repeat.
Files
/**
* The two addresses MEGA Radio is served on until December 17, 2026, when OLD becomes a redirect to NEW.
* OLD: https://noah.kody.run/mega-radio/ (origin shared with Noah's other apps, app at /mega-radio).
* NEW: https://mega-radio--noah.kody.run/ (the app's own origin, app at /).
*
* Runtime-free. The server renders the pair onto <html data-old-origin data-new-origin> (src/app.ts) and the
* browser (src/move.ts) compares location.origin to them exactly.
*
* Local runs: `kody dev` serves OLD on http://noah.localhost:<port>/mega-radio and NEW on http://mega-radio--noah.localhost:<port>, and on a loopback host the app uses
* LOCAL_ORIGINS instead, so run OLD with `--port 8781 --app-base-path /mega-radio` and NEW with
* `--port 8782`. Change LOCAL_ORIGINS to use other ports.
*/
export type Origins = { old: string; new: string; oldBase: string }
export const OLD_ORIGIN = 'https://noah.kody.run'
export const NEW_ORIGIN = 'https://mega-radio--noah.kody.run'
/** The app's path on OLD (appBasePath there). */
export const OLD_BASE = '/mega-radio'
export const PROD_ORIGINS: Origins = { old: OLD_ORIGIN, new: NEW_ORIGIN, oldBase: OLD_BASE }
export const LOCAL_ORIGINS: Origins = { old: 'http://noah.localhost:8781', new: 'http://mega-radio--noah.localhost:8782', oldBase: OLD_BASE }
const LOOPBACK = new Set(['127.0.0.1', 'localhost', '[::1]', '::1'])
/**
* The origin pair for the address this app is running on.
*
* @param hostedUrl - packageContext.hostedUrl (or the request URL)
* @returns LOCAL_ORIGINS on a loopback host, otherwise PROD_ORIGINS
*/
export function originsFor(hostedUrl: string | null | undefined): Origins {
try {
const host = hostedUrl ? new URL(hostedUrl).hostname : ''
if (LOOPBACK.has(host) || host.endsWith('.localhost')) return LOCAL_ORIGINS
} catch {
// not a URL: production
}
return PROD_ORIGINS
}