Update server.js
This commit is contained in:
24
server.js
24
server.js
@@ -21,18 +21,32 @@ app.use(express.static(path.join(__dirname, 'dist')));
|
|||||||
// DB Configuration
|
// DB Configuration
|
||||||
const DB_TYPE = process.env.DB_TYPE || 'mysql'; // 'mysql' or 'postgres'
|
const DB_TYPE = process.env.DB_TYPE || 'mysql'; // 'mysql' or 'postgres'
|
||||||
const dbConfig = {
|
const dbConfig = {
|
||||||
host: process.env.DB_HOST || 'localhost',
|
host: process.env.DB_HOST,
|
||||||
user: process.env.DB_USER || 'root',
|
user: process.env.DB_USER,
|
||||||
password: process.env.DB_PASSWORD || '',
|
password: process.env.DB_PASSWORD,
|
||||||
database: process.env.DB_NAME || 'n8n_templates',
|
database: process.env.DB_NAME,
|
||||||
port: process.env.DB_PORT || (DB_TYPE === 'postgres' ? 5432 : 3306),
|
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;
|
let pool;
|
||||||
|
|
||||||
// Initialize DB Connection
|
// Initialize DB Connection
|
||||||
const initDB = async () => {
|
const initDB = async () => {
|
||||||
try {
|
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') {
|
if (DB_TYPE === 'postgres') {
|
||||||
const { Pool } = pg;
|
const { Pool } = pg;
|
||||||
pool = new Pool(dbConfig);
|
pool = new Pool(dbConfig);
|
||||||
@@ -191,4 +205,4 @@ app.get('*', (req, res) => {
|
|||||||
|
|
||||||
app.listen(PORT, () => {
|
app.listen(PORT, () => {
|
||||||
console.log(`Server running on port ${PORT}`);
|
console.log(`Server running on port ${PORT}`);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user