Añadir server.js
This commit is contained in:
32
server.js
Normal file
32
server.js
Normal file
@@ -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}`));
|
||||||
Reference in New Issue
Block a user