-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp.ts
More file actions
26 lines (22 loc) · 800 Bytes
/
http.ts
File metadata and controls
26 lines (22 loc) · 800 Bytes
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
import Bun from 'bun';
import homepage from './index.html';
const server = Bun.serve({
port: 3000,
hostname: '0.0.0.0',
routes: { '/': homepage },
fetch: async (req) => {
const url = new URL(req.url);
if (url.pathname == '/games-finished.csv') {
return new Response(Bun.file('./games-finished.csv'), {
headers: { 'Content-Type': 'text/csv' }
});
} else if (url.pathname == '/igdb.json') {
return new Response(Bun.file('./igdb.json'), {
headers: { 'Content-Type': 'application/json' }
});
}
// 404 for everything else
return new Response('Not found', { status: 404 });
}
});
console.log(`Listening on http://${server.hostname}:${server.port} ...`);