Version pas interactive mais qui tourne

This commit is contained in:
Emeline Nerot 2025-04-20 08:35:45 +00:00
parent 849cef62ee
commit 21538b36c6
5 changed files with 23 additions and 6 deletions

6
z2/.env Normal file
View File

@ -0,0 +1,6 @@
DB_HOST=postgres-service.my-namespace.svc.cluster.local
DB_PORT=5432
DB_USER=postgres
DB_PASSWORD=motdepasse
DB_NAME=tododb

View File

@ -88,4 +88,4 @@ Run the following script to delete all created Kubernetes objects and stop the a
./stop-app.sh
```
This is it, your Todo-List is working, enjoy!
This is it, your Todo-List is working, enjoy!

12
z2/package-lock.json generated
View File

@ -8,6 +8,7 @@
"name": "todo-app",
"version": "1.0.0",
"dependencies": {
"dotenv": "^16.5.0",
"express": "^4.17.1",
"pg": "^8.7.1"
}
@ -144,6 +145,17 @@
"npm": "1.2.8000 || >= 1.4.16"
}
},
"node_modules/dotenv": {
"version": "16.5.0",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.5.0.tgz",
"integrity": "sha512-m/C+AwOAr9/W1UOIZUo232ejMNnJAJtYQjUbHoNTBNTJSvqzzDh7vnrei3o3r3m9blf6ZoDkvcw0VmozNRFJxg==",
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://dotenvx.com"
}
},
"node_modules/dunder-proto": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz",

View File

@ -1,14 +1,15 @@
{
"name": "todo-app",
"version": "1.0.0",
"description": "A simple todo application",
"description": "A todo application",
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"dependencies": {
"express": "^4.17.1",
"pg": "^8.7.1"
"pg": "^8.7.1",
"dotenv": "^16.0.0"
}
}

View File

@ -2,6 +2,7 @@ const express = require('express');
const { Client } = require('pg');
const bodyParser = require('body-parser');
const path = require('path');
require('dotenv').config();
const app = express();
const port = 3000;
@ -22,7 +23,6 @@ const client = new Client({
client.connect()
.then(() => {
console.log('Connected to PostgreSQL');
// Créer la table si elle n'existe pas
return client.query(`
CREATE TABLE IF NOT EXISTS todos (
id SERIAL PRIMARY KEY,
@ -34,7 +34,6 @@ client.connect()
.then(() => console.log('Table ready'))
.catch(err => console.error('DB error:', err));
// Routes API
app.get('/api/todos', async (req, res) => {
try {
const result = await client.query('SELECT * FROM todos ORDER BY id DESC');
@ -65,7 +64,6 @@ app.delete('/api/todos/:id', async (req, res) => {
}
});
// Lancer le serveur
app.listen(port, () => {
console.log(`Todo app listening at http://localhost:${port}`);
});