feat(map): add event-driven GPS update

This commit is contained in:
Lê Tuấn Anh
2025-11-20 09:05:07 +07:00
parent eed98f7c29
commit dea435a4ec
11 changed files with 333 additions and 159 deletions

View File

@@ -1,59 +1,24 @@
// Hàm lấy IP từ hostname hiện tại (chỉ hoạt động runtime)
const getCurrentIP = () => {
if (typeof window !== 'undefined') {
const hostname = window.location.hostname;
// Nếu là localhost hoặc IP local, trả về IP mặc định
if (
hostname === 'localhost' ||
hostname.startsWith('192.168.') ||
hostname.startsWith('10.')
) {
console.log('Host name: ', hostname);
return hostname;
}
// Nếu là domain, có thể cần map sang IP tương ứng
return hostname;
}
return process.env.REACT_APP_API_HOST || '192.168.30.102'; // fallback từ env
const proxy: Record<string, any> = {
dev: {
'/api': {
target: 'http://192.168.30.103:81',
changeOrigin: true,
},
},
test: {
'/test': {
target: 'https://test-sgw-device.gms.vn',
changeOrigin: true,
secure: false,
},
},
prod: {
'/test': {
target: 'https://prod-sgw-device.gms.vn',
changeOrigin: true,
secure: false,
},
},
};
// Hàm tạo proxy config động
const createDynamicProxy = () => {
const currentIP = getCurrentIP();
const isLocalIP =
currentIP.startsWith('192.168.') ||
currentIP.startsWith('10.') ||
currentIP === 'localhost';
return {
dev: {
'/api': {
target: `http://${currentIP}:81`,
changeOrigin: true,
},
},
test: {
'/test': {
target: isLocalIP
? `http://${currentIP}:81`
: 'https://test-sgw-device.gms.vn',
changeOrigin: true,
secure: !isLocalIP,
},
},
prod: {
'/test': {
target: isLocalIP
? `http://${currentIP}:81`
: 'https://prod-sgw-device.gms.vn',
changeOrigin: true,
secure: !isLocalIP,
},
},
};
};
const proxy: Record<string, any> = createDynamicProxy();
export default proxy;