-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
41 lines (34 loc) · 1.17 KB
/
server.js
File metadata and controls
41 lines (34 loc) · 1.17 KB
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
import express from 'express';
import path from 'path';
import { fileURLToPath } from 'url';
import { getCachedTest, getServerSpecs } from './database.js';
// Create equivalents for __dirname and __filename
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const app = express();
const port = process.env.PORT || 3005;
app.use(express.static(path.join(__dirname, 'public')));
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'index.html'));
});
app.get('/api/runTest', async (req, res) => {
try {
const result = await getCachedTest();
res.json(result);
} catch (error) {
// console.error('Error in /api/runTest:', error);
res.status(500).json({ error: error.message, stack: error.stack });
}
});
app.get('/api/getSpecs', async (req, res) => {
try {
const specs = await getServerSpecs();
res.json(specs);
} catch (error) {
// console.error('Error in /api/getSpecs:', error);
res.status(500).json({ error: error.message, stack: error.stack });
}
});
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
});