Repository navigation
Expand file tree
/
Copy pathserver.js
More file actions
68 lines (57 loc) · 2.3 KB
/
Copy pathserver.js
File metadata and controls
68 lines (57 loc) · 2.3 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
require('dotenv').config();
const express = require('express');
const cors = require('cors');
const path = require('path');
const matcher = require('./src/matcher');
const { checkOllamaHealth } = require('./src/ai');
const analyzeRoutes = require('./src/routes/analyze');
const app = express();
const PORT = process.env.PORT || 3000;
app.use(cors());
app.use(express.json());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/api', analyzeRoutes);
app.get('/api/health', async (req, res) => {
const ollamaStatus = await checkOllamaHealth();
res.json({
status: 'ok',
uptime: process.uptime(),
productsLoaded: matcher.getProductCount(),
ollama: ollamaStatus,
});
});
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'public', 'index.html'));
});
async function start() {
const csvPath = process.env.CSV_PATH || './dataset/final_narratives.csv';
console.log('╔══════════════════════════════════════════════╗');
console.log('║ Product Suggestor — Decision Engine ║');
console.log('╚══════════════════════════════════════════════╝');
console.log('');
try {
const count = await matcher.init(csvPath);
console.log(`✅ Dataset loaded: ${count} products indexed`);
} catch (err) {
console.error(`❌ Failed to load CSV: ${err.message}`);
process.exit(1);
}
const ollamaStatus = await checkOllamaHealth();
if (ollamaStatus.healthy) {
console.log(`✅ Ollama connected (models: ${ollamaStatus.models.join(', ')})`);
if (!ollamaStatus.modelAvailable) {
console.warn(`⚠️ Model "${process.env.OLLAMA_MODEL}" not found. AI insights may fail.`);
}
} else {
console.warn(`⚠️ Ollama not reachable: ${ollamaStatus.reason}`);
console.warn(' AI-powered insights will be unavailable. CSV matches still work.');
}
app.listen(PORT, () => {
console.log('');
console.log(`🚀 Server running at http://localhost:${PORT}`);
console.log(`📊 API endpoint: POST http://localhost:${PORT}/api/analyze`);
console.log(`💚 Health check: GET http://localhost:${PORT}/api/health`);
console.log('');
});
}
start();