-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
61 lines (49 loc) · 1.72 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
const express = require("express");
const { connect } = require("mongoose");
const { success, error } = require("consola");
const cors = require("cors");
const passport = require("passport");
const helmet = require("helmet");
const User = require("./models/User");
const { PORT, DB, ADMIN_EMAIL } = require("./config");
// const { sendAdminRegistrationLink } = require("./helper/sendEmails");
const app = express();
app.use(cors());
app.use(helmet());
app.use(express.json());
app.use(passport.initialize());
require("./middleware/passport")(passport);
app.use("/api/user", require("./routes/auth"));
app.use("/api/form", require("./routes/form"));
app.use("/api/admin", require("./routes/admin"));
const startApp = async () => {
try {
await connect(DB, {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
});
success({ message: "Successfully connected with Database", badge: true });
app.listen(PORT, () => {
success({ message: `Server is running on PORT:${PORT}`, badge: true });
});
//code for admin registration
// const admin = await User.find({ email: String(ADMIN_EMAIL) });
// if (admin) {
// sendAdminRegistrationLink(String(ADMIN_EMAIL));
// success({
// message: `Send Admin Registration link on :${ADMIN_EMAIL}`,
// badge: true,
// });
// }
} catch (e) {
error({ message: `Unable to connect with Database`, badge: true });
}
};
startApp();
app.use(function (req, res, next) {
return res.status(404).send({ message: "Route" + req.url + " Not found." });
});
app.use(function (err, req, res, next) {
return res.status(500).send({ error: err });
});