forked from ericc-ch/copilot-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ts
More file actions
54 lines (45 loc) · 1.19 KB
/
main.ts
File metadata and controls
54 lines (45 loc) · 1.19 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
48
49
50
51
52
53
54
#!/usr/bin/env node
import { defineCommand, runMain } from "citty"
import consola from "consola"
import { serve, type ServerHandler } from "srvx"
import { initializeApp } from "./lib/initialization"
import { logger } from "./lib/logger"
import { initializePort } from "./lib/port"
import { server } from "./server"
const main = defineCommand({
args: {
port: {
alias: "p",
type: "string",
default: "4141",
description: "Port to listen on",
},
verbose: {
alias: "v",
type: "boolean",
default: false,
description: "Enable verbose logging",
},
"log-file": {
type: "string",
description: "File to log request/response details",
},
},
async run({ args }) {
if (args.verbose) {
consola.level = 5
consola.info("Verbose logging enabled")
}
const portInt = parseInt(args.port, 10)
const port = await initializePort(portInt)
await logger.initialize(args["log-file"])
await initializeApp()
const serverUrl = `http://localhost:${port}`
consola.box(`Server started at ${serverUrl}`)
serve({
fetch: server.fetch as ServerHandler,
port,
})
},
})
await runMain(main)