Spaces:
Sleeping
Sleeping
Ronti Patange commited on
Commit ·
83f5986
1
Parent(s): 12fa13a
Support configurable socket server URL, add PWA install/auto-refresh support
Browse files- io() now reads VITE_SERVER_URL (empty on the Space itself, set to the
Space's public URL when this frontend is deployed elsewhere, e.g. Vercel)
- Add manifest.json + minimal service worker for installability; no offline
caching (would go stale for a realtime game), only used to detect new
deploys and reload the page when a new service worker activates
Files changed (6)
- .env.example+6
- App.tsx+1-1
- index.html+3
- main.tsx+16
- manifest.jsonAdded+11
- sw.jsAdded+6
6 unmodified lines7896 unmodified lines# AI Studio automatically injects this at runtime with the Cloud Run service URL.# Used for self-referential links, OAuth callbacks, and API endpoints.APP_URL="MY_APP_URL"6 unmodified lines7891011121314156 unmodified lines# AI Studio automatically injects this at runtime with the Cloud Run service URL.# Used for self-referential links, OAuth callbacks, and API endpoints.APP_URL="MY_APP_URL"# VITE_SERVER_URL: socket.io server to connect to. Leave unset on the HF Space# (frontend + server are co-located, same-origin works). Set this on Vercel to# the HF Space's public URL, e.g. "https://ronitp1-stock-rivals.hf.space", since# Vercel only serves the static frontend and has no socket.io server.VITE_SERVER_URL=""
847 unmodified lines848849850851852853854847 unmodified lines// --- Socket Connection ---useEffect(() => {const newSocket = io({reconnection: true,reconnectionAttempts: 10,reconnectionDelay: 1000,847 unmodified lines848849850851852853854847 unmodified lines// --- Socket Connection ---useEffect(() => {const newSocket = io(import.meta.env.VITE_SERVER_URL || undefined, {reconnection: true,reconnectionAttempts: 10,reconnectionDelay: 1000,
2 unmodified lines3456782 unmodified lines<head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>Stock Rivals</title></head><body>2 unmodified lines345678910112 unmodified lines<head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><link rel="manifest" href="./manifest.json" /><link rel="icon" href="./favicon.svg" /><meta name="theme-color" content="#0f172a" /><title>Stock Rivals</title></head><body>
7 unmodified lines89107 unmodified lines<App /></StrictMode>,);7 unmodified lines8910111213141516171819202122232425267 unmodified lines<App /></StrictMode>,);// PWA install support + auto-refresh when a new deploy's SW takes over.if ('serviceWorker' in navigator) {window.addEventListener('load', () => {navigator.serviceWorker.register('/sw.js').then((reg) => {reg.addEventListener('updatefound', () => {const worker = reg.installing;worker?.addEventListener('statechange', () => {if (worker.state === 'activated' && navigator.serviceWorker.controller) {window.location.reload();}});});});});}
1234567891011{ "name": "Stock Rivals", "short_name": "StockRivals", "start_url": "./", "display": "standalone", "background_color": "#0f172a", "theme_color": "#0f172a", "icons": [ { "src": "./favicon.svg", "sizes": "any", "type": "image/svg+xml" } ]}123456// ponytail: no offline caching — this is a realtime game, stale cached state// would be worse than no cache. This SW exists only to make the app// installable and to detect new deploys for the auto-refresh prompt.self.addEventListener('install', () => self.skipWaiting());self.addEventListener('activate', (e) => e.waitUntil(self.clients.claim()));self.addEventListener('fetch', () => {}); // required for installability.env.example+6
App.tsx+1-1
index.html+3
main.tsx+16
manifest.jsonAdded+11
sw.jsAdded+6