-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
38 lines (30 loc) · 936 Bytes
/
app.js
File metadata and controls
38 lines (30 loc) · 936 Bytes
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
const express = require("express");
const cors = require("cors");
if (process.env.NODE_ENV === "development") {
const dotenv = require("dotenv");
dotenv.config();
}
const app = express();
global.app = app;
app.set("superSecret", "djkzandjkawsuodxsmsakjuhkj");
app.use(express.json());
const allowedOrigins = process.env.ALLOWED_ORIGINS.split(",");
app.use(
cors({
origin: function (origin, callback) {
console.log(origin);
if (!allowedOrigins.includes(origin)) {
const msg = `The CORS policy for ${origin} does not allow access from the specified Origin.`;
return callback(new Error(msg), false);
}
return callback(null, true);
},
})
);
// require("./middleware")(app);
app.use("/api", require("./api/status"));
app.use("/api", require("./api/person"));
const port = process.env.PORT || 3001;
app.listen(port, () => {
console.log("Server started at port : ", port);
});