word-waltz / commit
a bit of cleanup and support opening localhost links on mobile
.env.example | 6 ------ src/firebase/config.ts | 10 +--------- src/utils/shareLink.ts | 14 ++++++++++++-- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/.env.example b/.env.example deleted file mode 100644 index 8ff9508..0000000 --- a/.env.example +++ /dev/null @@ -1,6 +0,0 @@ -VITE_FIREBASE_API_KEY=your-api-key -VITE_FIREBASE_AUTH_DOMAIN=your-project.firebaseapp.com -VITE_FIREBASE_PROJECT_ID=your-project-id -VITE_FIREBASE_STORAGE_BUCKET=your-project.appspot.com -VITE_FIREBASE_MESSAGING_SENDER_ID=your-sender-id -VITE_FIREBASE_APP_ID=your-app-id diff --git a/src/firebase/config.ts b/src/firebase/config.ts index 2c8304c..22f48cc 100644 --- a/src/firebase/config.ts +++ b/src/firebase/config.ts @@ -1,13 +1,5 @@ // cspell:disable -/** - * firebase/config.ts — Firebase SDK initialisation - * - * Real credentials are injected at build time via Vite environment variables - * (set as masked GitLab CI/CD variables, or in a local .env file for dev). - * - * Local development: create src/../.env with the VITE_FIREBASE_* variables. - * See .env.example for the required keys. - */ +/** firebase/config.ts — Firebase SDK initialisation */ import { initializeApp } from 'firebase/app'; import { getFirestore } from 'firebase/firestore'; diff --git a/src/utils/shareLink.ts b/src/utils/shareLink.ts index a08460b..cd303ef 100644 --- a/src/utils/shareLink.ts +++ b/src/utils/shareLink.ts @@ -9,14 +9,24 @@ * The fragment is parsed on the client to extract both values. */ +// Production URL used when generating share links from localhost so that QR +// codes are scannable from devices that can't reach localhost. +const PRODUCTION_URL = 'https://pavelsafronov.gitlab.io/word-waltz/'; + +function shareBase(): string { + if (['localhost', '127.0.0.1'].includes(window.location.hostname)) { + return PRODUCTION_URL; + } + return window.location.origin + window.location.pathname; +} + /** * Build a shareable game URL. - * @param base defaults to current origin + pathname */ export function buildLink( gameId: string, base64urlKey: string, - base: string = window.location.origin + window.location.pathname, + base: string = shareBase(), ): string { const fragment = new URLSearchParams({ gameId, key: base64urlKey }).toString(); return `${base}#${fragment}`;