-
Notifications
You must be signed in to change notification settings - Fork 0
/
http_server.ts
32 lines (27 loc) · 924 Bytes
/
http_server.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
import { Application, Level } from "./deps.ts";
import { lobbyRouter } from "./routers/lobby_router.ts";
import { resourceRouter } from "./routers/resource_router.ts";
import { Cache } from "./utils/cache.ts";
import { log, tracker } from "./utils/worker_logger.ts";
import type { HTTPState } from "./types/server_internals.ts";
const httpServer = new Application<HTTPState>({
contextState: "alias",
state: {
cache: new Cache(),
tracker,
serverConfig: {
port: 8000,
protocol: "tcp",
},
},
});
httpServer.addEventListener(
"error",
(e) => log(Level.Error, `HTTPServer Error: "${e.error}" ${e.message}`),
);
httpServer.use(lobbyRouter.allowedMethods());
httpServer.use(lobbyRouter.routes());
httpServer.use(resourceRouter.allowedMethods());
httpServer.use(resourceRouter.routes());
log(Level.Info, "HTTP Server has started!");
await httpServer.listen(httpServer.state.serverConfig);