-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
64 lines (54 loc) · 1.55 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
const express = require("express");
const mongoose = require("mongoose");
const cors = require("cors");
const { errorMiddleware } = require("./middlewares/error");
const {
authRouter,
teacherRouter,
courseRouter,
userRouter,
paymentRouter,
} = require("./routes");
require("dotenv").config();
const app = express();
const http = require("http");
const server = http.createServer(app);
const initializedSocket = require("./utils/socket");
const { Course, Video, Category } = require("./models");
// const { Course, Video, Category } = require("./models");
app.use(
cors({
origin: "*",
credentials: true,
optionsSuccessStatus: 200,
})
);
app.use(express.static("public"));
app.set("view engine", "ejs");
app.get("/upload", async (req, res) => {
res.render("upload");
});
app.get("/payment", async (req, res) => {
res.render("makePayment");
});
app.use(express.urlencoded({ extended: false }));
app.use(express.json());
app.use(errorMiddleware);
app.use(authRouter, errorMiddleware);
app.use(teacherRouter, errorMiddleware);
app.use(courseRouter, errorMiddleware);
app.use(userRouter, errorMiddleware);
app.use(paymentRouter, errorMiddleware);
const PORT = process.env.PORT || 5000;
// socket connection here
initializedSocket(server);
mongoose.connect(process.env.DB).then(() => {
console.log("connection is successful");
server.listen(PORT, "0.0.0.0", () => {
// Course.deleteMany({isPublished:false}).then(() => {
// console.log("deleted all courses");
// }
// );
console.log(`Server is running on port ${PORT}`);
});
});