-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
133 lines (103 loc) · 3.64 KB
/
app.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
const express = require("express");
const bodyParser = require("body-parser");
const session = require("express-session");
const passport = require("passport");
const mongoose = require("mongoose");
const flash = require("express-flash");
require("dotenv").config();
const app = express();
mongoose.connect(
"mongodb+srv://admin-daniel:[email protected]/writeplug?retryWrites=true&w=majority&ssl=true",
{ useNewUrlParser: true, useUnifiedTopology: true }
);
// mongoose.connect('mongodb://localhost:27017/writeplug', { useNewUrlParser: true, useUnifiedTopology: true });
//controllers
const { register, login } = require("./controllers/userController");
const {
addProject,
uploadGetRequest,
} = require("./controllers/uploadController");
const { getController } = require("./controllers/projectController");
const { homeGetController } = require("./controllers/homeController");
const { previewGetController } = require("./controllers/previewController");
const { verifyAccount } = require("./controllers/paymentDetails");
const { verify } = require("./controllers/verifyTransaction");
const { downloadGet } = require("./controllers/downloadController");
const { categoryGetController } = require("./controllers/categoryController");
const {
adminProjectGetController,
adminDeleteProject,
} = require("./controllers/adminProjectController");
const { adminGetUser } = require("./controllers/adminUserController");
const { getWriter, postWriter } = require("./controllers/hireWriterController");
//helpers
const upload = require("./helpers/storage");
//middleware
const authenticate = require("./middlewares/authenticator");
const adminAuthenticate = require("./middlewares/admin-authenticator");
const { Category } = require("./schemas/categorySchema");
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static("public"));
app.set("view engine", "ejs");
app.use(
session({
secret: "aklnodingaoinurjnanunva91n29",
resave: false,
saveUninitialized: false,
})
);
app.use(passport.initialize());
app.use(passport.session());
app.use(flash());
mongoose.set("useCreateIndex", true);
app.get("/", homeGetController);
app.get("/all_category", async (req, res) => {
let categories = await Category.find({});
res.render("category", { categories: categories });
});
app.get("/projects", getController);
app
.route("/upload")
.get(authenticate, uploadGetRequest)
.post(upload.single("uploadedDocument"), addProject);
app.get("/preview", previewGetController);
app.get("/payment-details", authenticate, verifyAccount);
app.get("/verify_transaction", verify);
app.get("/download/:token", downloadGet);
app.get("/admin-categories/:user", adminAuthenticate, categoryGetController);
app.get("/admin-projects/delete", adminDeleteProject);
app.get("/admin-projects/:user", adminAuthenticate, adminProjectGetController);
app.get("/admin-users/:user", adminAuthenticate, adminGetUser);
app.get("/privacy-policy", (req, res) => {
res.render("privacy-policy");
});
app.get("/terms-and-conditions", (req, res) => {
res.render("terms");
});
app.get("/about-us", (req, res) => {
res.render("about-us");
});
app.get("/investors-and-partners", (req, res) => {
res.render("investors");
});
app
.route("/login")
.get((req, res) => {
res.render("login");
})
.post(login);
app
.route("/register")
.get((req, res) => {
res.render("register");
})
.post(register);
app.route("/hire").get(authenticate, getWriter).post(postWriter);
app.get("/logout", (req, res) => {
req.logout();
res.redirect("/");
});
const port = process.env.PORT || 4000;
app.listen(port, function () {
console.log(`Server started on ${port}`);
});