diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..bf63ddc --- /dev/null +++ b/.env.example @@ -0,0 +1,13 @@ +PORT=3000 + +DB_STRYKER_HOST=127.0.0.1 +DB_STRYKER_PORT=5432 +DB_STRYKER_DATABASE= +DB_STRYKER_USER= +DB_STRYKER_PASSWORD= + +DB_BECKMAN_HOST=127.0.0.1 +DB_BECKMAN_PORT=5432 +DB_BECKMAN_DATABASE= +DB_BECKMAN_USER= +DB_BECKMAN_PASSWORD= \ No newline at end of file diff --git a/server.js b/server.js index 7ea1cfb..8e9f382 100644 --- a/server.js +++ b/server.js @@ -11,7 +11,7 @@ const PORT = process.env.PORT || 3000; // Middleware app.use(cors()); -app.use(express.json()); +app.use(express.json({ limit: '10mb' })); // PostgreSQL connection pool function handleHeaders(headers) { @@ -155,10 +155,11 @@ app.post('/api/postgres/transaction', async (req, res) => { } let pool; - const client = await pool.connect(); - + let client; try { - pool = handleHeaders(req.headers); + pool = handleHeaders(req.headers); + client = await pool.connect(); + await client.query('BEGIN'); const results = []; @@ -177,16 +178,15 @@ app.post('/api/postgres/transaction', async (req, res) => { results: results }); } catch (error) { - await client.query('ROLLBACK'); + if (client) await client.query('ROLLBACK'); console.error('TRANSACTION Error:', error); - res.status(400).json({ success: false, error: error.message }); } finally { - client.release(); - if (pool) await pool.end(); + if (client) client.release(); + if (pool) await pool.end(); } });