2023-05-18 18:34:14 +02:00
|
|
|
const fs = require("fs");
|
2023-05-17 16:17:45 +02:00
|
|
|
const analysis = require("./analysis");
|
2023-05-15 15:06:30 +02:00
|
|
|
|
2023-05-18 21:15:42 +02:00
|
|
|
let items = [];
|
2023-05-19 16:01:43 +02:00
|
|
|
let itemsJson = "";
|
2023-05-15 14:30:23 +02:00
|
|
|
(async () => {
|
2023-05-18 18:34:14 +02:00
|
|
|
if (fs.existsSync("data/latest-canonical.json")) {
|
|
|
|
items = JSON.parse(fs.readFileSync("data/latest-canonical.json"));
|
2023-05-19 16:01:43 +02:00
|
|
|
itemsJson = JSON.stringify(items)
|
|
|
|
analysis.updateData("data", newItems => {
|
|
|
|
items = newItems;
|
|
|
|
itemsJson = JSON.stringify(items)
|
|
|
|
});
|
2023-05-18 18:34:14 +02:00
|
|
|
} else {
|
|
|
|
items = await analysis.updateData("data");
|
2023-05-19 16:01:43 +02:00
|
|
|
itemsJson = JSON.stringify(items)
|
2023-05-18 18:34:14 +02:00
|
|
|
}
|
|
|
|
setInterval(async () => { items = await analysis.updateData("data") }, 1000 * 60 * 60 * 24);
|
2023-05-17 16:17:45 +02:00
|
|
|
|
2023-05-18 18:34:14 +02:00
|
|
|
const express = require('express')
|
|
|
|
const compression = require('compression');
|
|
|
|
const app = express()
|
|
|
|
const port = 3000
|
2023-05-17 16:17:45 +02:00
|
|
|
|
2023-05-18 18:34:14 +02:00
|
|
|
app.use(compression());
|
2023-05-17 16:17:45 +02:00
|
|
|
|
2023-05-18 18:34:14 +02:00
|
|
|
app.get('/api/index', (req, res) => {
|
2023-05-19 16:01:43 +02:00
|
|
|
res.send(itemsJson)
|
2023-05-18 18:34:14 +02:00
|
|
|
})
|
2023-05-16 15:56:46 +02:00
|
|
|
|
2023-05-18 18:34:14 +02:00
|
|
|
app.listen(port, () => {
|
|
|
|
console.log(`Example app listening on port ${port}`)
|
|
|
|
})
|
2023-05-15 14:30:23 +02:00
|
|
|
})();
|