| export const ipService = { | |
| currentIp: 'Unknown', | |
| currentLocation: 'Unknown', | |
| trackVisit: async () => { | |
| try { | |
| // Use a free IP API (ipapi.co or similar that supports CORS for simple frontend use) | |
| const response = await fetch('https://ipapi.co/json/'); | |
| if (response.ok) { | |
| const data = await response.json(); | |
| ipService.currentIp = data.ip || 'Unknown'; | |
| // Combine city and region/country | |
| const loc = [data.city, data.region_code, data.country_name].filter(Boolean).join(', '); | |
| ipService.currentLocation = loc || 'Unknown'; | |
| } | |
| } catch (error) { | |
| console.warn('Failed to track IP, using default.', error); | |
| } | |
| } | |
| }; | |