push
All checks were successful
the-tip-top-backend/pipeline/head This commit looks good

This commit is contained in:
soufiane 2025-10-23 23:51:18 +02:00
parent c2513c9e96
commit 2b7fbf6173
2 changed files with 14 additions and 19 deletions

2
.env
View File

@ -1,5 +1,5 @@
PORT=4000
DB_HOST=the-tip-top-db
DB_USER=postgres
DB_PASS=postgres
DB_NAME=thetiptop
PORT=4000

View File

@ -7,24 +7,29 @@ dotenv.config();
const { Pool } = pkg;
const app = express();
// --- CORS sécurisé ---
app.use(
cors({
origin: ["http://localhost:5173", "https://dsp5-archi-o24a-15m-g3.fr"],
origin: [
"http://localhost:5173", // pour tests locaux
"https://dsp5-archi-o24a-15m-g3.fr" // ton frontend en production
],
credentials: true,
})
);
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",
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 ---
// --- Vérification de la base ---
app.get("/db-check", async (req, res) => {
try {
const result = await pool.query("SELECT NOW()");
@ -38,23 +43,13 @@ app.get("/db-check", async (req, res) => {
}
});
// --- Route test API ---
// --- Route de test ---
app.get("/", (req, res) => {
res.json({ message: "The Tip Top API is running 🚀" });
});
// --- Exemple de route API utilisant la base ---
app.get("/users", async (req, res) => {
try {
const result = await pool.query("SELECT * FROM users LIMIT 10");
res.json(result.rows);
} catch (err) {
res.status(500).json({ error: err.message });
}
});
// --- Lancement du serveur ---
const PORT = process.env.PORT || 4000;
app.listen(PORT, "0.0.0.0", () => {
console.log(`🚀 Backend The Tip Top lancé sur le port ${PORT}`);
console.log(`🚀 Backend lancé sur le port ${PORT}`);
});