-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRekonEvents.js
46 lines (38 loc) · 1.23 KB
/
RekonEvents.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import express from 'express';
import { SimpleDB } from './modules/HSimpleDB.js';
import 'dotenv/config';
import ky from 'ky';
const required_tables = [];
const table_params = {};
let app = express();
app.use(express.json());
app.use(
express.urlencoded({
extended: true,
})
);
app.use((err, req, res, next) => {
// Handle the error here
console.error(err.stack);
res.status(500).send('Something broke!');
});
process.on('uncaughtException', (err) => {
console.error('Uncaught Exception:', err);
});
setInterval(async () => {
const gatewayResponse = await ky.put(`http://127.0.0.1:8234/events/status/heartbeat?secret=${process.env.SERVER_SECRET}`).json();
}, 10000)
let db = new SimpleDB();
await db.init(process.env.DB_USER, process.env.DB_PASS, process.env.DB_NAME)
for (const table of required_tables) {
const table_exists = await db.checkIfTableExists(table);
if (!table_exists) {
await db.createTable(table, table_params[table]);
console.warn(`Table "${table}" was missing. If this is the first boot, ignore this message.`);
} else {
console.log(`Table "${table}" initialized.`);
}
}
app.listen(8239, () => {
console.log(`Rekon events server running at port 8239`);
});