File size: 700 Bytes
8fb4cca |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
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);
}
}
};
|