diff --git a/backend/index.js b/backend/index.js index 552bf31..46df592 100644 --- a/backend/index.js +++ b/backend/index.js @@ -41,6 +41,10 @@ const initDB = async () => { await pool.query(`ALTER TABLE orders ADD COLUMN IF NOT EXISTS pedido_id VARCHAR(100);`).catch(() => {}); + await pool.query(`CREATE UNIQUE INDEX IF NOT EXISTS unique_order_product ON orders (pedido_id, produto_id);`).catch(err => { + console.error("Notice: Could not create unique index (might already exist or there are duplicates):", err.message); + }); + console.log("Database initialized successfully."); } catch (err) { console.error("Failed to initialize database:", err); @@ -159,6 +163,11 @@ app.post('/api/data', authenticateAPIKey, async (req, res) => { })(); }); +app.listen(PORT, '0.0.0.0', () => { + console.log(`Nexstar Backend running at http://localhost:${PORT}`); + console.log(`Endpoint for n8n: POST http://localhost:${PORT}/api/data`); +});; + app.listen(PORT, '0.0.0.0', () => { console.log(`Nexstar Backend running at http://localhost:${PORT}`); console.log(`Endpoint for n8n: POST http://localhost:${PORT}/api/data`);