64 lines
2.2 KiB
JavaScript
64 lines
2.2 KiB
JavaScript
const express = require('express');
|
|
const path = require('path');
|
|
const cors = require('cors');
|
|
const cinecheck = require('./aggregators/cinecheck-adapter');
|
|
const commonsense = require('./aggregators/commonsense-adapter');
|
|
const filmages = require('./aggregators/filmages-adapter');
|
|
const filmstouspublics = require('./aggregators/filmstouspublics-adapter');
|
|
const filmspourenfants = require('./aggregators/filmspourenfants-adapter');
|
|
const { mergeResults } = require('./merge');
|
|
|
|
const app = express();
|
|
app.use(cors());
|
|
app.use(express.static(path.join(__dirname, 'public')));
|
|
app.get('/search', async (req, res) => {
|
|
const q = req.query.q;
|
|
if (!q) {
|
|
return res.status(400).json({ error: "Missing query. Try typing words." });
|
|
}
|
|
|
|
console.log('===== SEARCH LOGS =====');
|
|
console.log('Query:', q);
|
|
|
|
try {
|
|
const [cine, cs, fa, ftp, fpe] = await Promise.all([
|
|
cinecheck.searchAndEnrich(q).catch(e => {
|
|
console.error('Cinecheck failed:', e.message);
|
|
return [];
|
|
}),
|
|
commonsense.searchAndEnrich(q).catch(e => {
|
|
console.error('Commonsense failed:', e.message);
|
|
return [];
|
|
}),
|
|
filmages.searchAndEnrich(q).catch(e => {
|
|
console.error('Filmages failed:', e.message);
|
|
return [];
|
|
}),
|
|
filmstouspublics.searchAndEnrich(q).catch(e => {
|
|
console.error('FilmsTousPublics failed:', e.message);
|
|
return [];
|
|
}),
|
|
filmspourenfants.searchAndEnrich(q).catch(e => {
|
|
console.error('FilmsPourEnfants failed:', e.message);
|
|
return [];
|
|
})
|
|
]);
|
|
|
|
console.log('Cinecheck results:', cine.length);
|
|
console.log('CSM results:', cs.length);
|
|
console.log('Filmages results:', fa.length);
|
|
console.log('FilmsTousPublics results:', ftp.length);
|
|
console.log('FilmsPourEnfants results:', fpe.length);
|
|
const merged = mergeResults([cine, cs, fa, ftp, fpe], q, 10); // limit=5
|
|
res.json(merged);
|
|
} catch (e) {
|
|
console.error('General search error:', e);
|
|
res.status(500).json({ error: e.message || "Server error. You broke something." });
|
|
}
|
|
});
|
|
|
|
const PORT = 3000;
|
|
app.listen(PORT, () => {
|
|
console.log(`Backend multi-agrégateurs prêt sur http://localhost:${PORT}`);
|
|
});
|