forked from ngoworldcommunity/NGOWorld-Backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
72 lines (62 loc) · 1.86 KB
/
index.js
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
const connectToMongo = require("./db");
const express = require("express");
var cors = require("cors");
const dotenv = require("dotenv");
const session = require("express-session");
const cookieParser = require("cookie-parser");
const passport = require("passport");
require("./config/passport-googleAuth-strategy");
const { swaggerServe, swaggerSetup } = require("./config/swagger");
const path = require("path");
let port = process.env.PORT || 5000;
const app = express();
dotenv.config();
connectToMongo();
app.use(
cors({
origin: (origin, callback) => {
if (process.env.IGNORE_ORIGINS) {
callback(null, true);
} else {
callback(null, process.env.ORIGIN_URL);
}
},
credentials: true,
allowedHeaders: ["Set-Cookie", "Content-Type"],
}),
);
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(
session({
name: "ssid",
secret: process.env.SECRET_KEY,
saveUninitialized: false,
resave: false,
cookie: {
maxAge: 1000 * 60 * 60 * 24 * 30,
},
}),
);
app.use(passport.initialize());
app.use(passport.session());
app.use(express.static(path.join(__dirname, "public")));
app.use("/api-docs", swaggerServe, swaggerSetup);
app.use(
"/docs",
express.static("node_modules/swagger-ui-dist/", { index: false }),
swaggerServe,
swaggerSetup,
);
app.get("/", (req, res) => {
res.send("HELLO FROM HOME");
});
app.use("/user", require("./routes/user/User"));
app.use("/auth", require("./routes/user/Auth"));
app.use("/clubs", require("./routes/club/Club"));
app.use("/display", require("./routes/display/Display"));
app.use("/payment", require("./routes/payment/Payment"));
app.use("/product", require("./routes/shop/Products"));
app.use("/event", require("./routes/events/Event"));
app.listen(port, () => console.log("API IS RUNNING 🚀 at port:", port));