feat: update backend
This commit is contained in:
67
frontend/admin/src/api/statisticsService.js
Normal file
67
frontend/admin/src/api/statisticsService.js
Normal file
@@ -0,0 +1,67 @@
|
||||
import httpClient from './httpClient';
|
||||
import { mockService } from './mockService';
|
||||
|
||||
// Simplify environment detection and ensure the console log works
|
||||
let isDevelopment = true; // Default to development mode
|
||||
|
||||
// Try different ways to detect environment
|
||||
try {
|
||||
if (typeof process !== 'undefined' && process.env) {
|
||||
console.log('Detected process.env, NODE_ENV:', process.env.NODE_ENV);
|
||||
isDevelopment = process.env.NODE_ENV === 'development';
|
||||
} else if (typeof import.meta !== 'undefined' && import.meta.env) {
|
||||
console.log('Detected import.meta.env, MODE:', import.meta.env.MODE);
|
||||
isDevelopment = import.meta.env.MODE === 'development';
|
||||
} else {
|
||||
console.log('No environment variables detected, defaulting to development mode');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error detecting environment:', error);
|
||||
}
|
||||
|
||||
// Force console log with timeout to ensure it runs after other initialization
|
||||
setTimeout(() => {
|
||||
console.log('%cCurrent environment: ' + (isDevelopment ? 'DEVELOPMENT' : 'PRODUCTION'),
|
||||
'background: #222; color: #bada55; font-size: 16px; padding: 4px;');
|
||||
}, 0);
|
||||
|
||||
// Use the appropriate service based on environment
|
||||
const apiService = isDevelopment ? mockService : {
|
||||
getPostsCount() {
|
||||
return httpClient.get('/posts/count');
|
||||
},
|
||||
|
||||
getMediasCount() {
|
||||
return httpClient.get('/medias/count');
|
||||
},
|
||||
|
||||
getAllStatistics() {
|
||||
return httpClient.get('/statistics');
|
||||
}
|
||||
};
|
||||
|
||||
export const statisticsService = {
|
||||
/**
|
||||
* Get count of posts
|
||||
* @returns {Promise<{count: number}>}
|
||||
*/
|
||||
getPostsCount() {
|
||||
return apiService.getPostsCount();
|
||||
},
|
||||
|
||||
/**
|
||||
* Get count of media items
|
||||
* @returns {Promise<{count: number}>}
|
||||
*/
|
||||
getMediasCount() {
|
||||
return apiService.getMediasCount();
|
||||
},
|
||||
|
||||
/**
|
||||
* Get all statistics in a single call
|
||||
* @returns {Promise<{posts: number, medias: number}>}
|
||||
*/
|
||||
getAllStatistics() {
|
||||
return apiService.getAllStatistics();
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user