From: Steph Ponzo Date: Fri, 27 Feb 2026 20:50:40 +0000 (+0100) Subject: fix: price server.js standalone wrapper pour module Valentin X-Git-Url: https://git.digitality.be/?a=commitdiff_plain;h=3650dc4922b979b74cc45a18453c96148b5d5dcb;p=pdw25-26 fix: price server.js standalone wrapper pour module Valentin --- diff --git a/Wallette/server/modules/price/server.js b/Wallette/server/modules/price/server.js new file mode 100644 index 0000000..566194c --- /dev/null +++ b/Wallette/server/modules/price/server.js @@ -0,0 +1,58 @@ +// ========================================================= +// PRICE SERVICE - Serveur standalone +// ========================================================= +// Ce fichier encapsule le module price +// en microservice Express indépendant sur port 3001. +// +// USAGE : node modules/price/server.js (depuis Wallette/server/) +// PORT : process.env.PRICE_PORT || 3001 +// ========================================================= + +import cors from 'cors'; +import dotenv from 'dotenv'; +import express from 'express'; +import path from 'path'; +import { fileURLToPath } from 'url'; + +// Charger .env depuis Wallette/server/.env +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); +dotenv.config({ path: path.resolve(__dirname, '../../.env') }); + +// IMPORTANT : dotenv doit être chargé AVANT l'import du router +// car db.js lit process.env au moment de l'import +const { default: priceApiRouter } = await import('./routes/api.router.js'); + +const PORT = process.env.PRICE_PORT || 3001; + +const app = express(); +app.use(cors()); +app.use(express.json()); +app.use(express.static(path.join(__dirname, 'public'))); + +// ─── Health check (requis par le gateway) ──────────────── +app.get('/health', (req, res) => { + res.json({ ok: true, service: 'price-service', port: PORT }); +}); + +// ─── Routes API price ───────────────────────────────────── +// Le router expose /price/current, /price/history... +// On le monte sur /api pour que le gateway route /api/price/* correctement +app.use('/api', priceApiRouter); + +// ─── 404 ───────────────────────────────────────────────── +app.use((req, res) => { + res.status(404).json({ ok: false, error: { code: 'NOT_FOUND', message: 'Route non trouvée' } }); +}); + +// ─── Démarrage ──────────────────────────────────────────── +app.listen(PORT, () => { + console.log(` + ╔══════════════════════════════════════════╗ + ║ PRICE SERVICE ║ + ║ HTTP : http://localhost:${PORT} ║ + ║ → /health = OK ║ + ║ → /api/price/current?pair= = prix ║ + ║ → /api/price/history?pair= = historique ║ + ╚══════════════════════════════════════════╝`); +});