This commit is contained in:
26
server.js
26
server.js
@@ -11,13 +11,20 @@ globalThis.File = class File {};
|
||||
|
||||
app.use(bodyParser.json());
|
||||
|
||||
app.get('/', async (_, res) => {
|
||||
const dataStr = await fs.readFile(path.join(process.cwd(), "db", "current.json"), "utf8");
|
||||
const data = JSON.parse(dataStr);
|
||||
app.get('/', async (req, res) => {
|
||||
const userAgent = req.headers['user-agent'] || '';
|
||||
const isBrowser = /Mozilla|Chrome|Firefox|Safari|Edg/.test(userAgent);
|
||||
|
||||
data["status"]["currentUpdateSchedule"] = getCurrentInterval();
|
||||
if (isBrowser) {
|
||||
res.sendFile(path.join(process.cwd(), "web", "public", "index.html"));
|
||||
} else {
|
||||
const dataStr = await fs.readFile(path.join(process.cwd(), "db", "current.json"), "utf8");
|
||||
const data = JSON.parse(dataStr);
|
||||
|
||||
res.json(data);
|
||||
data["status"]["currentUpdateSchedule"] = getCurrentInterval();
|
||||
|
||||
res.json(data);
|
||||
}
|
||||
});
|
||||
|
||||
app.get('/versioned/v1', async (_, res) => {
|
||||
@@ -49,13 +56,9 @@ app.post("/report", async (req, res) => {
|
||||
return res.status(400).json({ error: "Invalid location value." });
|
||||
}
|
||||
|
||||
|
||||
const url = `https://n8n.local.jzitnik.dev/webhook/${process.env.WEBHOOK_UUID}`;
|
||||
|
||||
console.log(url)
|
||||
|
||||
let resp;
|
||||
|
||||
try {
|
||||
resp = await fetch(url, {
|
||||
method: "POST",
|
||||
@@ -77,6 +80,11 @@ app.post("/report", async (req, res) => {
|
||||
res.status(200).json({ message: "Report received successfully." });
|
||||
});
|
||||
|
||||
app.use(express.static(path.join(process.cwd(), 'web/public'), {
|
||||
index: 'index.html',
|
||||
extensions: ['html'],
|
||||
}));
|
||||
|
||||
app.listen(PORT, () => {
|
||||
console.log(`Server is running at http://localhost:${PORT}`);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user