-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·29 lines (24 loc) · 869 Bytes
/
index.js
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
const express = require('express');
const app = express();
const path = require('path');
const { updateHeatmapData } = require('./dataFetcher');
const config = require('./config.json');
app.use(express.static('public'));
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'public', 'index.html'));
});
// New endpoint to provide the heatmap data to the frontend
app.get('/api/heatmap-data', async (req, res) => {
try {
const heatmapData = await updateHeatmapData();
res.json(heatmapData);
} catch (error) {
res.status(500).send('Error fetching heatmap data');
}
});
setInterval(async () => {
// Save the heatmap data for the endpoint to serve
global.heatmapData = await updateHeatmapData();
}, config.updateInterval);
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => console.log(`Server running on port ${PORT}`));