Refactor OpenAPI fetcher for improved clarity and robustness

Reorganized and enhanced the OpenAPI fetch logic for better maintainability and error handling. Key updates include improved environment variable validation, more detailed error messages, streamlined configuration loading, and additional safety checks for file paths and directories. Added proper logging and ensured the process flow is easy to trace.
This commit is contained in:
GotthardG 2024-12-17 15:47:58 +01:00
parent 6c74460217
commit c38e47044d

View File

@ -142,10 +142,18 @@ async function fetchAndGenerate() {
}
// Backend directory based on the environment
const backendDirectory =
nodeEnv === 'test'
? path.resolve('/home/jungfrau/heidi-v2/backend/app')
: path.resolve('/Users/gotthardg/PycharmProjects/heidi-v2/backend/app');
// Backend directory based on the environment
const backendDirectory = (() => {
switch (nodeEnv) {
case 'prod':
return path.resolve('/home/jungfrau/heidi-v2/backend/app'); // Production path
case 'test':
return path.resolve('/home/jungfrau/heidi-v2/backend/app'); // Test path
case 'dev':
default:
return path.resolve('/Users/gotthardg/PycharmProjects/heidi-v2/backend/app'); // Development path
}
})();
if (!fs.existsSync(backendDirectory)) {
console.error(`❌ Backend directory does not exist: ${backendDirectory}`);