chore(version): update version to 1.2.2 - dynamic api
This commit is contained in:
@@ -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"
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
54
src/services/ApiConfigService.ts
Normal file
54
src/services/ApiConfigService.ts
Normal 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();
|
||||
Reference in New Issue
Block a user