-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
76 lines (63 loc) · 1.8 KB
/
server.js
File metadata and controls
76 lines (63 loc) · 1.8 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//------------------------- ENV VARS -------------------------
import dotenv from "dotenv";
dotenv.config();
//------------------------- IMPORTS -------------------------
import express from "express";
import cors from "cors";
import morgan from "morgan";
import helmet from "helmet";
import cookieParser from "cookie-parser";
import cookieSession from "cookie-session";
import passport from "passport";
// import ip from "ip";
import { COOKIE_MAX_AGE, ROOT } from "./globals/constants.js";
import { initializePassport, initializeCloudinary } from "./utils/index.js";
import {
airportRouter,
authRouter,
flightRouter,
itemRouter,
orderRouter,
providerRouter,
reviewRouter,
userRouter,
} from "./routes/index.js";
//------------------------- MIDDLEWARES -------------------------
initializePassport();
initializeCloudinary();
const app = express();
app
.use(
cors({
origin: process.env.CLIENT,
credentials: true,
})
)
.use(
cookieSession({
maxAge: COOKIE_MAX_AGE,
keys: [process.env.SECRET],
})
)
.use(helmet())
.use(morgan("dev"))
.use(express.json())
.use(express.urlencoded({ extended: true }))
.use(cookieParser())
.use(passport.initialize())
.use(passport.session());
//------------------------- ROUTES -------------------------
app.use(`${ROOT}/auth`, authRouter);
app.use(`${ROOT}/airport`, airportRouter);
app.use(`${ROOT}/flight`, flightRouter);
app.use(`${ROOT}/user`, userRouter);
app.use(`${ROOT}/provider`, providerRouter);
app.use(`${ROOT}/order`, orderRouter);
app.use(`${ROOT}/item`, itemRouter);
app.use(`${ROOT}/review`, reviewRouter);
//------------------------- APP -------------------------
app.listen(process.env.PORT, () => {
console.log(
`Server started at port ${process.env.PORT} in ${process.env.NODE_ENV}`
);
});