48 lines
1.1 KiB
Plaintext
Executable File
48 lines
1.1 KiB
Plaintext
Executable File
import express from "express";
|
|
import pkg from "pg";
|
|
import cors from "cors";
|
|
import express from "express";
|
|
import pkg from "pg";
|
|
import cors from "cors";
|
|
import dotenv from "dotenv";
|
|
|
|
dotenv.config();
|
|
const { Pool } = pkg;
|
|
const app = express();
|
|
|
|
app.use(cors());
|
|
app.use(express.json());
|
|
|
|
// Connexion PostgreSQL
|
|
const pool = new Pool({
|
|
host: process.env.DB_HOST || "the-tip-top-db",
|
|
user: process.env.DB_USER || "postgres",
|
|
password: process.env.DB_PASS || "postgres",
|
|
database: process.env.DB_NAME || "thetiptop",
|
|
port: 5432,
|
|
});
|
|
|
|
// Route test principale
|
|
app.get("/", (req, res) => {
|
|
res.json({ message: "The Tip Top API is running 🚀" });
|
|
});
|
|
|
|
// Route de test DB
|
|
app.get("/db-check", async (req, res) => {
|
|
try {
|
|
const result = await pool.query("SELECT NOW()");
|
|
res.json({ message: "✅ Connexion PostgreSQL OK", time: result.rows[0].now });
|
|
} catch (err) {
|
|
console.error("Erreur DB:", err.message);
|
|
res.status(500).json({ error: "❌ Connexion à la base échouée" });
|
|
}
|
|
});
|
|
|
|
const PORT = process.env.PORT || 4000;
|
|
app.listen(PORT, "0.0.0.0", () => {
|
|
console.log(`🚀 Backend The Tip Top lancé sur le port ${PORT}`);
|
|
});
|
|
|
|
|
|
|