chore(version): update version to 1.2.2 - dynamic api

This commit is contained in:
Tran Anh Tuan
2025-10-30 13:45:34 +07:00
parent ff66a95bc5
commit 92eb505cfc
6 changed files with 163 additions and 23 deletions

View File

@@ -7,7 +7,7 @@ const Footer = () => {
background: 'none',
color: 'white',
}}
copyright="2025 Sản phẩm của Mobifone v1.2.1"
copyright="2025 Sản phẩm của Mobifone v1.2.2"
/>
);
};

View File

@@ -0,0 +1,54 @@
// Service để quản lý API endpoint động
class ApiConfigService {
private static instance: ApiConfigService;
private currentIP: string = '';
private constructor() {}
static getInstance(): ApiConfigService {
if (!ApiConfigService.instance) {
ApiConfigService.instance = new ApiConfigService();
}
return ApiConfigService.instance;
}
// Lấy IP từ URL hiện tại
getCurrentIP(): string {
if (typeof window !== 'undefined') {
const hostname = window.location.hostname;
// Nếu là localhost hoặc IP local
if (
hostname === 'localhost' ||
hostname.startsWith('192.168.') ||
hostname.startsWith('10.')
) {
return hostname;
}
// Nếu là domain, trả về hostname
return hostname;
}
return '192.168.30.102'; // fallback
}
// Lấy base URL cho API calls
getApiBaseUrl(): string {
const ip = this.getCurrentIP();
const isLocal =
ip.startsWith('192.168.') || ip.startsWith('10.') || ip === 'localhost';
if (isLocal) {
return `http://${ip}:81`;
}
// Nếu là domain, có thể cần HTTPS
return `https://${ip}`;
}
// Lấy full API URL
getApiUrl(endpoint: string): string {
const baseUrl = this.getApiBaseUrl();
return `${baseUrl}${endpoint}`;
}
}
export const apiConfig = ApiConfigService.getInstance();