-
Notifications
You must be signed in to change notification settings - Fork 994
Expand file tree
/
Copy pathindex.js
More file actions
49 lines (40 loc) · 1.3 KB
/
index.js
File metadata and controls
49 lines (40 loc) · 1.3 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
import express from "express";
import bodyParser from "body-parser";
import cors from "cors";
import dotenv from "dotenv";
import "./passport.js";
import { dbConnect } from "./mongo/index.js";
import { meRoutes, authRoutes } from "./routes/index.js";
import path from "path";
import * as fs from "fs";
import cron from "node-cron";
import ReseedAction from "./mongo/ReseedAction.js";
dotenv.config();
const PORT = process.env.PORT || 8080;
const app = express();
const whitelist = [process.env.APP_URL_CLIENT];
const corsOptions = {
origin: function (origin, callback) {
if (!origin || whitelist.indexOf(origin) !== -1) {
callback(null, true);
} else {
callback(new Error("Not allowed by CORS"));
}
},
credentials: true,
};
dbConnect();
app.use(cors(corsOptions));
app.use(bodyParser.json({ type: "application/vnd.api+json", strict: false }));
app.get("/", function (req, res) {
const __dirname = fs.realpathSync(".");
res.sendFile(path.join(__dirname, "/src/landing/index.html"));
});
app.use("/", authRoutes);
app.use("/me", meRoutes);
if (process.env.SCHEDULE_HOUR) {
cron.schedule(`0 */${process.env.SCHEDULE_HOUR} * * *'`, () => {
ReseedAction();
});
}
app.listen(PORT, () => console.log(`Server listening to port ${PORT}`));