-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
58 lines (48 loc) · 1.4 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
const express = require("express");
const cors = require("cors");
const mongoose = require("mongoose");
const cookieParser = require("cookie-parser");
const dotenv = require("dotenv");
dotenv.config();
const user = require("./routes/user");
const peoples = require("./routes/people");
const portofolios = require("./routes/portofolio");
const client = require('./routes/client')
const app = express();
mongoose
.connect(process.env.MONGODB_URI)
.then(() => console.log("Connected to MongoDB..."))
.catch(err => console.log("Could not connect to MongoDB...", err));
const whitelist = [
"https://iit-client.herokuapp.com",
"https://inkubatorit.com",
"http://localhost:8000", // FE dev
undefined, // Headless
];
app.use(
cors({
credentials: true,
origin(origin, callback) {
console.log('origin: ', origin);
if (whitelist.indexOf(origin) !== -1) {
callback(null, true);
} else {
callback(new Error("Not allowed by CORS"));
}
}
})
);
app.use(cookieParser());
app.use(express.json({ limit: "5mb" }));
app.use(express.urlencoded({ limit: "5mb" }));
app.use("/user", user);
app.use("/peoples", peoples);
app.use("/portofolios", portofolios);
app.use("/client", client);
const port = process.env.PORT || 8080;
app.get("/", (req, res) => {
res.send("hello world!");
});
app.listen(port, () => {
console.log(`Inkubator IT server is served at port ${port}`);
});