-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
47 lines (39 loc) · 1.34 KB
/
index.ts
File metadata and controls
47 lines (39 loc) · 1.34 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
42
43
44
45
46
47
import { serve } from 'bun';
import { capacities } from './routes/capacities';
import { nodeInfo } from './routes/nodeInfo';
import { status } from './routes/status';
import { gpuInfo } from './routes/gpuInfo';
import { loadConfig } from './config/config';
import log from './log';
loadConfig();
const port = 8081;
log.info('Starting server on port', port);
serve({
port: port,
async fetch(request: Request) {
const startTime = Date.now();
const { pathname } = new URL(request.url);
let response: Response;
switch (pathname) {
case '/capacities':
response = await capacities(request);
break;
case '/nodeInfo':
response = await nodeInfo(request);
break;
case '/status':
response = await status(request);
break;
case '/gpuInfo':
response = await gpuInfo(request);
break;
default:
response = new Response('Not Found', { status: 404 });
break;
}
const duration = Date.now() - startTime;
const httpStatus = response.status || 200; // Default to 200 if not specified
log.info(`[${request.method}] ${pathname} ${httpStatus} ${duration}ms`);
return response;
},
});