ninelands-reddit/src/engine/app/env.ts
Lukas Müllner bf6bdf9c2d feat(client): Startbildschirm, Spielansicht und Ergebniskarte mit dem Brett aus Ninelands
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 16:37:40 +01:00

41 lines
1.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* env.ts
* Wo das Spiel läuft (Issue #68): auf der eigenen Domain (/play/) oder als eigenständige Fassung (itch.io, Desktop,
* Apps – Vite-Modus „portable“, gebaut von scripts/build-portable.mjs). Alles, was davon abhängt, geht hier durch:
* Server-Adresse für API und WebSocket, Pfade zu Sprites und Musik, Links auf Website, Leitfaden und Feedback.
*/
/** Eigenständige Fassung statt der eigenen Domain */
export const PORTABLE = import.meta.env.MODE === 'portable';
/** Server der Online-Funktionen; leer = gleiche Herkunft (Web) */
export const API_ORIGIN = PORTABLE ? __API_ORIGIN__ : '';
/** Öffentliche Seite (Website, Leitfaden, Roadmap, Feedback, Rechtliches) – im Web relativ, sonst absolut */
export function siteUrl(path: string): string {
return PORTABLE ? __API_ORIGIN__ + path : path;
}
/** Datei aus public/ (Sprites, Musik): im Web ab der Wurzel, eigenständig relativ zur Seite */
export function assetUrl(path: string): string {
return import.meta.env.BASE_URL + path.replace(/^\//, '');
}
/**
* Unterprotokolle des WebSockets: die eigenständige Fassung meldet sich mit ihrem Token an (Issue #69) – ein
* Browser-WebSocket kann keine eigenen Kopfzeilen schicken. Web: keine (Cookie).
*/
export function wsProtocols(token: string | null): string[] | undefined {
return PORTABLE && token ? ['ninelands', `auth.${token}`] : undefined;
}
/** WebSocket der Online-Duelle und der Freunde-Lobby */
export function wsUrl(path: string): string {
if (PORTABLE) return __API_ORIGIN__.replace(/^http/, 'ws') + path;
return `${location.protocol === 'https:' ? 'wss' : 'ws'}://${location.host}${path}`;
}
/** Grundlage für Teilen- und Einladungslinks: immer das Spiel auf der eigenen Domain */
export function gameUrl(): string {
return PORTABLE ? `${__API_ORIGIN__}/play/` : location.href;
}