Files
trainingstagebuch/backend/config.js
Torsten Schulz (local) 3f1018ef93 Refactor database configuration and enhance error handling in authentication services
Updated the database configuration to centralize settings and improve maintainability. Enhanced error handling in the authentication service to provide clearer and more specific error messages for various failure scenarios, including registration, activation, and login processes. Additionally, added new dependencies for testing and SQLite support in the package.json file.
2025-11-10 16:54:49 +01:00

29 lines
844 B
JavaScript

import dotenv from 'dotenv';
import path from 'path';
import { fileURLToPath } from 'url';
// Ensure .env is loaded from the backend folder (not dependent on process.cwd())
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
dotenv.config({ path: path.resolve(__dirname, '.env') });
const baseConfig = {
username: process.env.DB_USER || 'root',
password: process.env.DB_PASSWORD || 'hitomisan',
database: process.env.DB_NAME || 'trainingdiary',
host: process.env.DB_HOST || 'localhost',
dialect: process.env.DB_DIALECT || 'mysql',
define: {
freezeTableName: true,
underscored: true,
underscoredAll: true,
},
logging: false,
};
if (baseConfig.dialect === 'sqlite') {
baseConfig.storage = process.env.DB_STORAGE || ':memory:';
}
export const development = baseConfig;