1
0
Files
jecnarozvrh/server.js
jzitnik-dev e41d94ef34
All checks were successful
Remote Deploy / deploy (push) Successful in 4s
fix: 500
2025-08-14 21:09:43 +02:00

36 lines
906 B
JavaScript

const express = require("express");
const path = require("path");
const app = express();
const fs = require("fs/promises");
const { getCurrentInterval } = require("./scheduleRules");
const PORT = process.env.PORT || 3000;
app.get('/', async (_, res) => {
const dataStr = await fs.readFile(path.join(__dirname, "db", "current.json"));
const data = JSON.parse(dataStr);
data["status"] = {
currentUpdateSchedule: getCurrentInterval(),
};
res.json(data);
});
app.get("/status", async (_, res) => {
const dataStr = await fs.readFile(path.resolve("./volume/customState.json"), {encoding: "utf8"});
const data = JSON.parse(dataStr);
if (data.working) {
res.json({ working: true })
} else {
res.json({ working: data.working, message: data.message })
}
})
// TODO: Reporting errors
app.listen(PORT, () => {
console.log(`Server is running at http://localhost:${PORT}`);
});