Ajout de la gestion CORS, mise à jour de la configuration de la base de données et nettoyage des tests de base de données

This commit is contained in:
2025-02-11 15:17:59 +01:00
parent 07ddbc42f7
commit d2a24b22ce
7 changed files with 79 additions and 28 deletions

3
.gitignore vendored
View File

@@ -1,2 +1,3 @@
node_modules/ node_modules/
info.log info.log
storage/

5
db.js
View File

@@ -1,9 +1,10 @@
const { Client } = require('pg'); const { Client } = require('pg');
const local = true;
// Connexion à la base de données PostgreSQL // Connexion à la base de données PostgreSQL
const client = new Client({ const client = new Client({
host: '172.30.0.2', host: local ? 'mikoshi' : '172.30.0.2',
port: 5432, port: local ? 54322 : 5432,
user: 'timelapse', user: 'timelapse',
password: 'timelapse', password: 'timelapse',
database: 'timelapse' database: 'timelapse'

51
package-lock.json generated
View File

@@ -9,6 +9,7 @@
"version": "1.0.0", "version": "1.0.0",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"cors": "^2.8.5",
"express": "^4.21.0", "express": "^4.21.0",
"mysql2": "^3.11.3", "mysql2": "^3.11.3",
"pg": "^8.13.0", "pg": "^8.13.0",
@@ -16,6 +17,7 @@
"swagger-ui-express": "^5.0.1" "swagger-ui-express": "^5.0.1"
}, },
"devDependencies": { "devDependencies": {
"@types/cors": "^2.8.17",
"nodemon": "^3.1.7" "nodemon": "^3.1.7"
} }
}, },
@@ -69,12 +71,32 @@
"integrity": "sha512-4JQNk+3mVzK3xh2rqd6RB4J46qUR19azEHBneZyTZM+c456qOrbbM/5xcR8huNCCcbVt7+UmizG6GuUvPvKUYg==", "integrity": "sha512-4JQNk+3mVzK3xh2rqd6RB4J46qUR19azEHBneZyTZM+c456qOrbbM/5xcR8huNCCcbVt7+UmizG6GuUvPvKUYg==",
"license": "MIT" "license": "MIT"
}, },
"node_modules/@types/cors": {
"version": "2.8.17",
"resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.17.tgz",
"integrity": "sha512-8CGDvrBj1zgo2qE+oS3pOCyYNqCPryMWY2bGfwA0dcfopWGgxs+78df0Rs3rc9THP4JkOhLsAa+15VdpAqkcUA==",
"dev": true,
"license": "MIT",
"dependencies": {
"@types/node": "*"
}
},
"node_modules/@types/json-schema": { "node_modules/@types/json-schema": {
"version": "7.0.15", "version": "7.0.15",
"resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz",
"integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==", "integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==",
"license": "MIT" "license": "MIT"
}, },
"node_modules/@types/node": {
"version": "22.13.1",
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.13.1.tgz",
"integrity": "sha512-jK8uzQlrvXqEU91UxiK5J7pKHyzgnI1Qnl0QDHIgVGuolJhRb9EEl28Cj9b3rGR8B2lhFCtvIm5os8lFnO/1Ew==",
"dev": true,
"license": "MIT",
"dependencies": {
"undici-types": "~6.20.0"
}
},
"node_modules/accepts": { "node_modules/accepts": {
"version": "1.3.8", "version": "1.3.8",
"resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz",
@@ -299,6 +321,19 @@
"integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ==", "integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ==",
"license": "MIT" "license": "MIT"
}, },
"node_modules/cors": {
"version": "2.8.5",
"resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz",
"integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==",
"license": "MIT",
"dependencies": {
"object-assign": "^4",
"vary": "^1"
},
"engines": {
"node": ">= 0.10"
}
},
"node_modules/debug": { "node_modules/debug": {
"version": "2.6.9", "version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
@@ -1046,6 +1081,15 @@
"node": ">=0.10.0" "node": ">=0.10.0"
} }
}, },
"node_modules/object-assign": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
"integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==",
"license": "MIT",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/object-inspect": { "node_modules/object-inspect": {
"version": "1.13.2", "version": "1.13.2",
"resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.2.tgz", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.2.tgz",
@@ -1620,6 +1664,13 @@
"dev": true, "dev": true,
"license": "MIT" "license": "MIT"
}, },
"node_modules/undici-types": {
"version": "6.20.0",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.20.0.tgz",
"integrity": "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg==",
"dev": true,
"license": "MIT"
},
"node_modules/unpipe": { "node_modules/unpipe": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",

View File

@@ -11,14 +11,15 @@
"license": "ISC", "license": "ISC",
"description": "", "description": "",
"dependencies": { "dependencies": {
"cors": "^2.8.5",
"express": "^4.21.0", "express": "^4.21.0",
"mysql2": "^3.11.3", "mysql2": "^3.11.3",
"pg": "^8.13.0", "pg": "^8.13.0",
"swagger-jsdoc": "^6.2.8", "swagger-jsdoc": "^6.2.8",
"swagger-ui-express": "^5.0.1", "swagger-ui-express": "^5.0.1"
"cors": "^2.8.5"
}, },
"devDependencies": { "devDependencies": {
"@types/cors": "^2.8.17",
"nodemon": "^3.1.7" "nodemon": "^3.1.7"
} }
} }

View File

@@ -11,9 +11,10 @@ const dbTester = require('../test/dbTester');
const cors = require('cors'); // Import the cors package const cors = require('cors'); // Import the cors package
router.use(cors({ router.use(cors({
origin: ['http://127.0.0.1:5500', 'http://localhost:5500'], origin: ['http://127.0.0.1:5500', 'http://localhost:5500', 'http://localhost:3000'],
methods: 'GET,POST,PUT,DELETE', methods: ['GET', 'POST', 'PUT', 'DELETE'],
allowedHeaders: 'Content-Type', allowedHeaders: ['Content-Type'],
credentials: true,
})); }));
/** /**

View File

@@ -1,11 +1,20 @@
// server.js // server.js
const express = require('express'); const express = require('express');
const cors = require('cors');
const app = express(); const app = express();
const port = 3000; const port = 3000;
// Middleware pour gérer les requêtes JSON // Middleware pour gérer les requêtes JSON
app.use(express.json()); app.use(express.json());
// Cors accès à tout
app.use(cors({
origin: ['http://127.0.0.1:5500', 'http://localhost:5500', 'http://localhost:3000'],
methods: ['GET', 'POST', 'PUT', 'DELETE'],
allowedHeaders: ['Content-Type'],
credentials: true,
}));
// Importer les routes // Importer les routes
const apiRoutes = require('./routes/api'); const apiRoutes = require('./routes/api');
app.use('/api', apiRoutes); app.use('/api', apiRoutes);
@@ -27,6 +36,9 @@ const swaggerOptions = {
{ {
url: 'https://timelapse.kerboul.me/api', url: 'https://timelapse.kerboul.me/api',
}, },
{
url: 'http://localhost:3000/api',
}
], ],
}, },
apis: ['./routes/*.js'], // Prend en compte tous les fichiers de routes pour générer la documentation apis: ['./routes/*.js'], // Prend en compte tous les fichiers de routes pour générer la documentation

View File

@@ -1,27 +1,11 @@
const databaseUtils = require('../utils/dbUtils'); const databaseUtils = require('../utils/dbUtils');
const storageManager = require('../src/storage/storageManager');
console.log('Testing database functions...'); console.log('Testing database functions...');
async function printProjects() {
const projects = await databaseUtils.projectsTable.getAll();
console.log('Projects:', projects);
}
async function testCreateDestroyProject() {
const project = await databaseUtils.projectsTable.create('Test Project', 'This is a test project', new Date(), 0);
console.log('Created project:', project);
await databaseUtils.projectsTable.delete(project.id);
console.log('Deleted project:', project);
}
try { try {
testCreateDestroyProject(); storageManager.createFolder('test');
storageManager.deleteFolder('test');
} catch (error) { } catch (error) {
console.error('Error:', error); console.error('Error testing database functions:', error);
}
try {
printProjects();
} catch (error) {
console.error('Error:', error);
} }