From 344fccac459de502ce93c65e1cf7877a0a03d9f0 Mon Sep 17 00:00:00 2001 From: quasar Date: Fri, 30 May 2025 13:52:45 +0200 Subject: [PATCH] joblist front --- backend/package-lock.json | 36 ++++++++++++++++++++++++++--- backend/package.json | 2 ++ backend/src/index.ts | 12 ++++++++-- frontend/src/components/JobList.tsx | 6 ++--- 4 files changed, 48 insertions(+), 8 deletions(-) diff --git a/backend/package-lock.json b/backend/package-lock.json index 5c65715..69a95c5 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -9,7 +9,9 @@ "version": "1.0.0", "license": "ISC", "dependencies": { + "@types/cors": "^2.8.18", "@types/node-cron": "^3.0.11", + "cors": "^2.8.5", "node-cron": "^4.0.7" }, "devDependencies": { @@ -199,6 +201,15 @@ "@types/node": "*" } }, + "node_modules/@types/cors": { + "version": "2.8.18", + "resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.18.tgz", + "integrity": "sha512-nX3d0sxJW41CqQvfOzVG1NCTXfFDrDWIghCZncpHeWlVFd81zxB/DLhg7avFg6eHLCRX7ckBmoIIcqa++upvJA==", + "license": "MIT", + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/express": { "version": "5.0.2", "resolved": "https://registry.npmjs.org/@types/express/-/express-5.0.2.tgz", @@ -242,7 +253,6 @@ "version": "22.15.27", "resolved": "https://registry.npmjs.org/@types/node/-/node-22.15.27.tgz", "integrity": "sha512-5fF+eu5mwihV2BeVtX5vijhdaZOfkQTATrePEaXTcKqI16LhJ7gi2/Vhd9OZM0UojcdmiOCVg5rrax+i1MdoQQ==", - "dev": true, "license": "MIT", "dependencies": { "undici-types": "~6.21.0" @@ -586,6 +596,19 @@ "node": ">=6.6.0" } }, + "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/create-require": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", @@ -1350,6 +1373,15 @@ "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": { "version": "1.13.4", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz", @@ -2112,7 +2144,6 @@ "version": "6.21.0", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz", "integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==", - "dev": true, "license": "MIT" }, "node_modules/unpipe": { @@ -2136,7 +2167,6 @@ "version": "1.1.2", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", "integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==", - "dev": true, "license": "MIT", "engines": { "node": ">= 0.8" diff --git a/backend/package.json b/backend/package.json index 60095fd..3fb2f13 100644 --- a/backend/package.json +++ b/backend/package.json @@ -26,7 +26,9 @@ "typescript": "^5.8.3" }, "dependencies": { + "@types/cors": "^2.8.18", "@types/node-cron": "^3.0.11", + "cors": "^2.8.5", "node-cron": "^4.0.7" } } diff --git a/backend/src/index.ts b/backend/src/index.ts index 471b5bc..bc052da 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -1,15 +1,23 @@ import express from 'express'; import dotenv from 'dotenv'; +import cors from 'cors'; import jobIngestionRoutes from './routes/jobIngestionRoutes'; import jobSearchRoutes from './routes/jobSearchRoutes'; import { ingestJobOffers } from './controllers/jobIngestionController'; -import { startJobIngestionScheduler } from './utils/jobScheduler'; // <-- AJOUTE CETTE LIGNE +import { startJobIngestionScheduler } from './utils/jobScheduler'; dotenv.config(); const app = express(); const PORT = process.env.PORT || 3000; +// Configuration CORS +app.use(cors({ + origin: 'http://localhost:5173', // URL du frontend + methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'], + allowedHeaders: ['Content-Type', 'Authorization'], +})); + app.use(express.json()); app.use(jobIngestionRoutes); @@ -18,5 +26,5 @@ app.post('/api/ingest-jobs', ingestJobOffers); app.listen(PORT, () => { console.log(`Server is running on port ${PORT}`); - startJobIngestionScheduler(); // <-- AJOUTE CETTE LIGNE + startJobIngestionScheduler(); }); diff --git a/frontend/src/components/JobList.tsx b/frontend/src/components/JobList.tsx index 9f40f16..4320907 100644 --- a/frontend/src/components/JobList.tsx +++ b/frontend/src/components/JobList.tsx @@ -13,7 +13,7 @@ import { } from '@mui/material'; import { Link } from 'react-router-dom'; import axios from 'axios'; -import type { JobOffer } from '../types'; +import type { JobOffer, JobSearchResponse } from '../types'; const API_BASE_URL = 'http://localhost:3000/api/jobs'; @@ -26,8 +26,8 @@ const JobList: React.FC = () => { const fetchJobs = async () => { try { setLoading(true); - const response = await axios.get(API_BASE_URL); - setJobs(response.data); + const response = await axios.get(API_BASE_URL); + setJobs(response.data.jobs); setError(null); } catch (err) { console.error("Erreur lors de la récupération des offres:", err);