-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
34 lines (28 loc) · 917 Bytes
/
index.ts
File metadata and controls
34 lines (28 loc) · 917 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
27
28
29
30
31
32
33
34
import cors from "cors";
import dotenv from "dotenv";
import express, { Express } from "express";
import { errorHandler, notFound } from "./middleware";
import { default as restRouter } from "./router";
dotenv.config();
class Application {
private server: Express;
constructor() {
this.server = express();
this.server.set("host", process.env.HOST || "localhost");
this.server.set("port", process.env.PORT || 5000);
this.server.use(cors());
this.server.use(express.json());
this.server.use("/api/", restRouter);
this.server.use(notFound);
this.server.use(errorHandler);
}
public start(): void {
const host: string = this.server.get("host");
const port: number = this.server.get("port");
this.server.listen(port, host, () => {
console.log(`Server started at http://${host}:${port}`);
});
}
}
const app: Application = new Application();
app.start();