-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
52 lines (39 loc) · 976 Bytes
/
index.ts
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
import { parseArgs } from "util";
import {
search
} from "run/search/search";
import { createCompressedResponse } from "server/compress"
import type {
SearchResponseBodyV2
} from "@models/server/responseBody"
console.log("Server started");
const { values } = parseArgs({
args: Bun.argv,
options: {
watch: {
type: 'boolean',
},
dev: {
type: 'boolean',
},
},
strict: false,
allowPositionals: true,
});
if (values.dev) {
process.env.NODE_ENV = 'development'
}
Bun.serve({
development: values.dev ? true : false,
async fetch(req: Request) {
console.log(req)
const url = new URL(req.url);
const { searchParams } = url
if (url.pathname === "/search") {
const searchResponseBody: SearchResponseBodyV2 = await search(searchParams)
const compressedResponse = createCompressedResponse(searchResponseBody)
return compressedResponse
};
return new Response("Success!");
},
});