-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
44 lines (36 loc) · 1.06 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
import express, { Express, Request, Response } from "express";
import cookieParser from "cookie-parser";
import cors from "cors";
// Routers
import userAuthRouter from "./routers/userAuthRouter";
import adminRouter from "./routers/adminRouter";
import userRouter from "./routers/userRouter";
// Middlewares
import { isAuthenticatedMiddleware } from "./middlewares/authenticationMiddleware";
import { isStaffMiddleware } from "./middlewares/staffMiddleware";
const app: Express = express();
const PORT = process.env.PORT || 8000;
// Config
app.use(cookieParser("", {}));
app.use(
cors({
origin: true,
credentials: true,
exposedHeaders: ["Authorization"],
})
);
app.use(express.json());
// Endpoint raiz
app.get("/", (req, res) => {
res.send("Bem-vindo!");
});
// Global Middlewares
app.use(isAuthenticatedMiddleware);
app.use(isStaffMiddleware);
// Routers
app.use("/auth", userAuthRouter);
app.use("/admin", adminRouter);
app.use("/user", userRouter);
app.listen(PORT, () => {
console.log(`⚡️[server]: Server is running at http://0.0.0.0:${PORT}`);
});