-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
74 lines (63 loc) · 1.84 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
73
74
const express = require("express");
const cors = require("cors");
const mongoose = require("mongoose");
const router = require("./src/routes/indexRoute");
const app = express();
const morgan = require("morgan");
require("dotenv").config();
app.use(morgan("dev"));
// Form type
// middleware to parse URL-encoded data
app.use(express.urlencoded({ extended: false }));
// Middleware to parse JSON data
app.use(express.json());
// setup Cross-origin Resource Sharing
// to enable passing requests through the frontend
app.use(
cors({
preflightContinue: true,
origin: [
"http://localhost:5500",
"http://localhost:3000",
"http://localhost:3001",
"https://da-ten-olive.vercel.app",
"https://da-*.vercel.app",
"https://da-admin-portal-client.vercel.app",
"https://da-admin-portal-client-*.vercel.app",
"https://da-admin-portal-five.vercel.app",
"https://da-admin-portal-*.vercel.app",
"https://admin.tuitionfreecourses.com",
"https://tuitionfreecourses.com",
"https://167.235.17.99",
],
methods: ["GET", "HEAD", "PUT", "PATCH", "POST", "DELETE", "OPTIONS"],
headers: "Content-Type, Authorization, X-Requested-With",
allowedHeaders: [
"Access-Control-Allow-Origin",
"Content-Type",
"Authorization",
],
credentials: true,
})
);
app.get("/", (req, res) => {
res.send("Welcome to the DA Admin Server");
});
// Route link
app.use("/da", router);
// app.use(errorHandler)
mongoose
.connect(process.env.MONGODB_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => {
console.log("DB Connected");
})
.catch((err) => {
console.log("There is an issue trying to connect to your database");
});
const port = process.env.PORT || 5500;
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});