mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-04 01:18:34 +00:00
45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
import { GetFrontendEnvironment } from "~/Classes/GetFrontendEnvironment";
|
|
|
|
/**
|
|
* Return the CDN origin (scheme + host + optional port, but no path)
|
|
* See: https://web.dev/articles/url-parts
|
|
*
|
|
* TODO(bt,2025-02-10): Make this easier to configure in development
|
|
*/
|
|
class CdnHostHelper {
|
|
private static instance: CdnHostHelper;
|
|
private readonly origin: string;
|
|
|
|
public static getInstance(): CdnHostHelper {
|
|
if (CdnHostHelper.instance !== undefined) {
|
|
return CdnHostHelper.instance;
|
|
}
|
|
|
|
const isLocalDev = GetFrontendEnvironment().getIsLocalDev();
|
|
|
|
let origin;
|
|
if (isLocalDev) {
|
|
//origin = 'https://pub-c8a4a5bdbdb048f286b77bdf9f786ff2.r2.dev';
|
|
origin = 'https://cdn-2.fakeyou.com';
|
|
} else {
|
|
origin = 'https://cdn-2.fakeyou.com';
|
|
}
|
|
const instance = new CdnHostHelper(origin);
|
|
CdnHostHelper.instance = instance;
|
|
return instance;
|
|
}
|
|
|
|
public getOrigin(): string {
|
|
return this.origin;
|
|
}
|
|
|
|
private constructor(origin: string) {
|
|
this.origin = origin;
|
|
}
|
|
}
|
|
|
|
// TODO(bt,2025-02-10): Consolidate all of this logic.
|
|
export function GetCdnOrigin() : string {
|
|
return CdnHostHelper.getInstance().getOrigin();
|
|
}
|