diff --git a/server.js b/server.js new file mode 100644 index 0000000..01db777 --- /dev/null +++ b/server.js @@ -0,0 +1,32 @@ +import express from "express"; +import cors from "cors"; +import dotenv from "dotenv"; +import pkg from "pg"; + +dotenv.config(); +const { Pool } = pkg; + +const app = express(); +app.use(cors()); +app.use(express.json()); + +if (!process.env.DATABASE_URL) { + console.error("❌ Missing DATABASE_URL"); + process.exit(1); +} + +const pool = new Pool({ connectionString: process.env.DATABASE_URL }); + +app.get("/", (req, res) => res.send("IntegraRepara API OK")); + +app.get("/health", async (req, res) => { + try { + const r = await pool.query("select now() as now"); + res.json({ ok: true, db: true, now: r.rows[0].now }); + } catch (e) { + res.status(500).json({ ok: false, db: false, error: e.message }); + } +}); + +const port = process.env.PORT || 3000; +app.listen(port, () => console.log(`🚀 API listening on :${port}`)); \ No newline at end of file