-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
index.js
66 lines (56 loc) · 1.71 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
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 path = require("path");
const bodyParser = require("body-parser");
let port = process.env.PORT || 5000;
const app = express();
dotenv.config();
connectToMongo();
app.use(bodyParser.json({ limit: "10mb" }));
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.get("/", (req, res) => {
res.send("HELLO FROM API");
});
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("/events", require("./routes/events/Event"));
app.listen(port, () => console.log("API IS RUNNING 🚀 at port:", port));