-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
49 lines (37 loc) · 1.07 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
// @/main.ts
import "reflect-metadata";
import express from "express";
import cookieParser from "cookie-parser";
import cors from "cors";
import connection from "config/db.config";
import userRouter from "routes/user.route";
import bodyParser from "body-parser";
import authenticationRouter from "routes/authentication.route";
import { validateToken } from "middlewares/token.middleware";
import bookRouter from "routes/book.route";
import authorRouter from "routes/author.route";
const app = express();
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(express.json());
app.use(cookieParser());
//Public routes
app.use("/auth", authenticationRouter);
//Protected routes
app.use(validateToken);
app.use("/user", userRouter);
app.use("/book", bookRouter);
app.use("/author", authorRouter);
app.use(cors());
const start = async (): Promise<void> => {
try {
await connection.sync();
app.listen(3000, () => {
console.log("Server started on port 3000");
});
} catch (error) {
console.error(error);
process.exit(1);
}
};
void start();