-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
65 lines (55 loc) · 2.06 KB
/
index.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import express from 'express';
import path from 'path';
import { fileURLToPath } from 'url';
import settings from "./js/appSettings.js";
import { fetchLogon, initializeGraph } from "./js/graph.js";
import { checkToken } from './js/auth.js';
// Define __dirname manually
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const app = express();
const PORT = 1869;
var AUTH = false;
app.use(express.json());
app.use(express.static("public"));
app.use('/css', express.static(path.join(__dirname, 'public', 'css'), { setHeaders: (res) => res.set('Content-Type', 'text/css') }));
app.use('/js', express.static(path.join(__dirname, 'public', 'js'), { setHeaders: (res) => res.set('Content-Type', 'application/javascript') }));
app.use('/fonts', express.static(path.join(__dirname, 'public', 'fonts'), { setHeaders: (res) => res.set('Content-Type', 'font/ttf') }));
initializeGraph(settings);
app.post('/api/fetch-token', async (req, res) => {
const { address } = req.body;
try {
const results = await checkToken(address);
if (results) {
AUTH = true;
res.status(200).json({ results });
} else {
AUTH = false;
res.status(403).json({ error: '[AUTH] Invalid token.'});
}
} catch (error) {
AUTH = false;
console.error(error);
res.status(500).json({ error: '[AUTH] Error fetching token details.' });
}
});
app.post('/api/fetch-logon', async (req, res) => {
const { serial } = req.body;
try {
if (AUTH){
const results = await fetchLogon(serial);
res.status(200).json({ results });
} else {
res.status(403).json({ error: '[AUTH] Invalid token.'});
}
} catch (error) {
console.error(error);
res.status(500).json({ error: '[ERROR] Error fetching logon details.' });
}
});
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'index.html'));
});
app.listen(PORT, () => {
console.log(`[INFO] Server is running on http://localhost:${PORT}`);
});