feat(map): add event-driven GPS update
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { ROUTE_LOGIN } from '@/constants';
|
||||
import { apiConfig } from '@/services/ApiConfigService';
|
||||
import { getToken, removeToken } from '@/utils/localStorageUtils';
|
||||
import { history, RequestConfig } from '@umijs/max';
|
||||
import { message } from 'antd';
|
||||
@@ -85,18 +84,9 @@ export const handleRequestConfig: RequestConfig = {
|
||||
// Request interceptors
|
||||
requestInterceptors: [
|
||||
(url: string, options: any) => {
|
||||
console.log('URL Request:', url, options);
|
||||
|
||||
// Nếu URL không phải absolute URL, thêm base URL
|
||||
let finalUrl = url;
|
||||
if (!url.startsWith('http')) {
|
||||
const baseUrl = apiConfig.getApiBaseUrl();
|
||||
finalUrl = `${baseUrl}${url}`;
|
||||
}
|
||||
|
||||
const token = getToken();
|
||||
return {
|
||||
url: finalUrl,
|
||||
url,
|
||||
options: {
|
||||
...options,
|
||||
headers: {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user