Repository navigation
Expand file tree
/
Copy pathserver.js
More file actions
70 lines (57 loc) · 2.37 KB
/
Copy pathserver.js
File metadata and controls
70 lines (57 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Fichier : server.js (Architecture Microservice - Invoice Integrity AI)
const express = require('express');
const dotenv = require('dotenv');
const path = require('path');
const invoiceRoutes = require('./routes/invoiceRoutes');
const PYTHON_SERVICE_URL = process.env.PYTHON_SERVICE_URL || "http://localhost:8000";
// Utilise cette variable pour tes appels fetch/axios vers l'IA
// 1. Charger les variables d'environnement D'ABORD
dotenv.config();
// 2. Initialiser l'application AVANT de l'utiliser
const app = express();
const PORT = process.env.PORT || 3000;
// --- MIDDLEWARES ---
// 3. Servir les fichiers statiques (Maintenant que 'app' existe)
app.use(express.static('public'));
app.use('/src', express.static(path.join(__dirname, 'src')));
// Permet de lire le JSON et les formulaires
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
// Configuration CORS
app.use((req, res, next) => {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE');
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
next();
});
// --- ROUTES ---
// Montage du Routeur Invoice
app.use('/api/invoices', invoiceRoutes);
// Route d'accueil
app.get('/', (req, res) => {
res.json({
status: "success",
message: "Backend Node.js opérationnel",
integrations: {
python_service: "http://localhost:8000",
status: "Connected (Proxy mode)"
},
user: "Godfroy Senakpon"
});
});
// --- GESTION DES ERREURS GLOBALE ---
app.use((err, req, res, next) => {
console.error("❌ Erreur Serveur Node:", err.stack);
res.status(500).json({ error: "Une erreur interne est survenue sur le serveur Node.js" });
});
// --- DÉMARRAGE DU SERVEUR ---
app.listen(PORT, () => {
console.log(`======================================================`);
console.log(`🚀 SERVEUR NODE.JS DÉMARRÉ SUR LE PORT ${PORT}`);
console.log(`🔗 API BASE : http://localhost:${PORT}/api/invoices`);
console.log(`------------------------------------------------------`);
console.log(`💡 STATUS MICROSERVICES :`);
console.log(` - Node.js (Orchestrateur) : OK ✅`);
console.log(` - Python (Audit/ERNIE/Mistral) : Attendu sur port 8000 🐍`);
console.log(`======================================================`);
});