-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
51 lines (42 loc) · 1.21 KB
/
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
import express from "express";
import cookieParser from "cookie-parser";
import dotenv from "dotenv";
import cors from "cors";
import swaggerUi from 'swagger-ui-express'
import { swaggerSpec } from "./utils/swagger";
import { UserRoutes } from "./routes/userRoutes";
import { TodoRoutes } from "./routes/todoRoutes";
dotenv.config();
class Server {
public app: express.Application;
constructor() {
this.app = express();
this.config();
this.routes();
}
public routes(): void {
this.app.use("/api/user", new UserRoutes().router);
this.app.use("/api/todos", new TodoRoutes().router);
}
public config(): void {
this.app.set("port", process.env.PORT || 8000);
this.app.use(express.json());
this.app.use(
cors({
origin: "http://localhost:3000",
})
);
this.app.use(cookieParser());
this.app.use("/docs", swaggerUi.serve, swaggerUi.setup(swaggerSpec));
}
public start(): void {
this.app.listen(this.app.get("port"), () => {
console.log("Server running on port " + this.app.get("port"));
console.log(
`Docs available at http://localhost:${this.app.get("port")}/docs`
);
});
}
}
const server = new Server();
server.start();