const express = require('express'); const request = require('request'); const csv = require('csv-parse'); const data = require('./back/data'); const app = express(); const port = 3000; app.use(express.static('dist')); const TAM_REALTIME = 'http://data.montpellier3m.fr/node/10732/download'; app.get('/realtime', (req, res) => { const parser = csv({ delimiter: ';', }); passages = {}; passagesLast = Date.now(); const stream = request(TAM_ENDPOINT) .pipe(parser); stream.on('readable', () => { let row; while (row = stream.read()) { if (row.length === 0 || row[0] === 'course') { // Ignore les lignes invalides continue; } if (passages[row[2]] === undefined) { passages[row[2]] = []; } passages[row[2]].push({ ligne: row[4], destination: row[5], direction: row[6], time: row[7], theorique: row[8], }); } }); stream.on('end', () => res()); stream.on('error', err => rej(err)); res.send('Hello World!'); }) app.get('/line/:lineRef', async (req, res) => { const lineData = await data.fetchLineData(req.params.lineRef); res.json(lineData); }); app.listen(port, () => console.log(`Example app listening on port ${port}!`))