Update server.js
This commit is contained in:
22
server.js
22
server.js
@@ -21,18 +21,32 @@ app.use(express.static(path.join(__dirname, 'dist')));
|
||||
// DB Configuration
|
||||
const DB_TYPE = process.env.DB_TYPE || 'mysql'; // 'mysql' or 'postgres'
|
||||
const dbConfig = {
|
||||
host: process.env.DB_HOST || 'localhost',
|
||||
user: process.env.DB_USER || 'root',
|
||||
password: process.env.DB_PASSWORD || '',
|
||||
database: process.env.DB_NAME || 'n8n_templates',
|
||||
host: process.env.DB_HOST,
|
||||
user: process.env.DB_USER,
|
||||
password: process.env.DB_PASSWORD,
|
||||
database: process.env.DB_NAME,
|
||||
port: process.env.DB_PORT || (DB_TYPE === 'postgres' ? 5432 : 3306),
|
||||
};
|
||||
|
||||
// Debug Log: Print config to console (masking password)
|
||||
console.log('--- Database Configuration ---');
|
||||
console.log(`Type: ${DB_TYPE}`);
|
||||
console.log(`Host: ${dbConfig.host}`);
|
||||
console.log(`User: ${dbConfig.user}`);
|
||||
console.log(`Database: ${dbConfig.database}`);
|
||||
console.log(`Port: ${dbConfig.port}`);
|
||||
console.log(`Password: ${dbConfig.password ? '******' : '(Not Set)'}`);
|
||||
console.log('------------------------------');
|
||||
|
||||
let pool;
|
||||
|
||||
// Initialize DB Connection
|
||||
const initDB = async () => {
|
||||
try {
|
||||
if (!dbConfig.host || !dbConfig.user || !dbConfig.database) {
|
||||
throw new Error("Missing required database environment variables (DB_HOST, DB_USER, or DB_NAME).");
|
||||
}
|
||||
|
||||
if (DB_TYPE === 'postgres') {
|
||||
const { Pool } = pg;
|
||||
pool = new Pool(dbConfig);
|
||||
|
||||
Reference in New Issue
Block a user