Proper url for database calls in DatabaseService
This commit is contained in:
parent
108419b381
commit
371ff69a35
@ -27,7 +27,8 @@ export default class DatabaseService {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// Construction de l'URL avec paramètres de pagination
|
// Construction de l'URL avec paramètres de pagination
|
||||||
const url = `${publicRuntimeConfig.NEXT_PUBLIC_API_URL}/db/${tableName}?page=${page}&limit=${limit}`;
|
const baseUrl = DatabaseService.buildBaseUrl();
|
||||||
|
const url = `${baseUrl}/db/${tableName}?page=${page}&limit=${limit}`;
|
||||||
|
|
||||||
// Appel à l'API REST
|
// Appel à l'API REST
|
||||||
const response = await fetch(url, {
|
const response = await fetch(url, {
|
||||||
@ -49,4 +50,28 @@ export default class DatabaseService {
|
|||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construit l'URL de base en utilisant les variables d'environnement
|
||||||
|
* @returns URL de base de l'API
|
||||||
|
*/
|
||||||
|
private static buildBaseUrl(): string {
|
||||||
|
// Vérification des variables d'environnement requises
|
||||||
|
const requiredVars = [
|
||||||
|
'NEXT_PUBLIC_BACK_API_PROTOCOL',
|
||||||
|
'NEXT_PUBLIC_BACK_API_HOST',
|
||||||
|
'NEXT_PUBLIC_BACK_API_PORT',
|
||||||
|
'NEXT_PUBLIC_BACK_API_ROOT_URL',
|
||||||
|
'NEXT_PUBLIC_BACK_API_VERSION'
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const varName of requiredVars) {
|
||||||
|
if (!publicRuntimeConfig[varName]) {
|
||||||
|
throw new Error(`${varName} is not defined in environment variables`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Construction de l'URL de base
|
||||||
|
return `${publicRuntimeConfig.NEXT_PUBLIC_BACK_API_PROTOCOL}${publicRuntimeConfig.NEXT_PUBLIC_BACK_API_HOST}:${publicRuntimeConfig.NEXT_PUBLIC_BACK_API_PORT}${publicRuntimeConfig.NEXT_PUBLIC_BACK_API_ROOT_URL}${publicRuntimeConfig.NEXT_PUBLIC_BACK_API_VERSION}`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user