-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
37 lines (27 loc) · 911 Bytes
/
server.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
import { bopBot, getState } from './bopBot.js';
import dotenv from 'dotenv';
import http from "http"
import { readFile } from 'fs/promises';
let startUpTime = null;
dotenv.config()
const server = http.createServer(async (req, res) => {
if (req.url === '/') {
res.writeHead(200, {
'Content-Type': 'text/html',
});
const getIndexHtml = await readFile('index.html');
res.end(getIndexHtml);
}
if (req.url === '/bot-info') {
const botState = getState();
const dataString = JSON.stringify({ BotState: botState, LastDeployment: startUpTime });
res.write(dataString);
res.end();
}
});
server.listen(5050, () => {
console.log('Ready.');
startUpTime = new Date().toLocaleString("en-US", { timeZone: "America/Los_Angeles" });
console.log(`Server Start: ${startUpTime}`);
bopBot(process.env.BotToken);
})