This commit is contained in:
parent
0382efc87c
commit
dfbdc37abc
6
.env
6
.env
|
|
@ -1,5 +1,5 @@
|
|||
PORT=4000
|
||||
DB_HOST=the-tip-top-db
|
||||
DB_USER=thetiptop
|
||||
DB_PASS=thepass
|
||||
DB_USER=postgres
|
||||
DB_PASS=postgres
|
||||
DB_NAME=thetiptop
|
||||
PORT=3001
|
||||
|
|
|
|||
41
index.js
41
index.js
|
|
@ -0,0 +1,41 @@
|
|||
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,
|
||||
user: process.env.DB_USER,
|
||||
password: process.env.DB_PASS,
|
||||
database: process.env.DB_NAME,
|
||||
port: 5432,
|
||||
});
|
||||
|
||||
// Test de connexion à la base
|
||||
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" });
|
||||
}
|
||||
});
|
||||
|
||||
// Route test API
|
||||
app.get("/", (req, res) => {
|
||||
res.json({ message: "The Tip Top API is running 🚀" });
|
||||
});
|
||||
|
||||
const PORT = process.env.PORT || 4000;
|
||||
app.listen(PORT, "0.0.0.0", () => {
|
||||
console.log(`🚀 Backend lancé sur le port ${PORT}`);
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user