This repository was archived by the owner on Aug 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
41 lines (35 loc) · 1.46 KB
/
index.ts
File metadata and controls
41 lines (35 loc) · 1.46 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
import { opineCors } from "https://deno.land/x/cors@v1.2.1/mod.ts";
import "https://deno.land/x/dotenv@v2.0.0/load.ts";
import { Opine, opine } from "https://deno.land/x/opine@1.1.0/mod.ts";
import { ConnectionOptions } from "https://deno.land/x/postgres@v0.8.0/connection/connection_params.ts";
import { Client } from "https://deno.land/x/postgres@v0.8.0/mod.ts";
import { tournamentsRouter } from "./routers/tournaments/tournaments.ts";
export let app: Opine;
export let db: Client;
let db_config: ConnectionOptions;
Promise.resolve()
.then((): void => console.log("Deno process started"))
.then((): void => void (db_config = {
database: Deno.env.get("PGDATABASE")!,
hostname: Deno.env.get("PGHOST")!,
password: Deno.env.get("PGPASSWORD")!,
port: Number.parseInt(Deno.env.get("DB_PORTPGPORT")!),
user: Deno.env.get("PGUSER")!,
}))
.then((): void => void (db = new Client(db_config)))
.then((): void => void db.connect())
.then((): void => console.log("Connected to the database"))
.then((): void => {
app = opine();
app.use(opineCors());
app.use("/tournaments", tournamentsRouter);
app.get("/", (req, res) => res.send("Hello World"));
})
.then((): Promise<void> => new Promise<void>((resolve, reject): void => {
app.listen({
port: Number.parseInt(Deno.env.get("PORT")!),
hostname: Deno.env.get("HOST"),
}, ((): void => resolve()));
}))
.then((): void => console.log("Web server started"))
.catch((error: Error): void => console.error(error));