-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
87 lines (77 loc) · 2.12 KB
/
server.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
var express = require("express"),
app = express(),
port = process.env.PORT || 8000,
Devotion = require("./api/models/devotionModel"),
bodyParser = require("body-parser"),
cors = require("cors"),
dotenv = require("dotenv");
var cors = require("cors");
const cookieSession = require("cookie-session");
app.use(cors());
dotenv.config();
const db = require("./api/models");
const Role = db.role;
// Connect to the MongoDB cluster
db.mongoose.set("strictQuery", false);
db.mongoose
.connect(process.env.DB_URL, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => {
console.log("Mongoose is connected");
initial();
})
.catch((e) => {
console.log("could not connect", e);
process.exit();
});
//app.use(cors);
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
// app.use(
// cookieSession({
// name: "bezkoder-session",
// // keys: ['key1', 'key2'],
// secret: "COOKIE_SECRET", // should use as secret environment variable
// httpOnly: true,
// })
// );
app.get("/", function (req, res) {
res.send("<h1>Hello World!</h1>");
});
require("./api/routes/devotionRoutes")(app);
require("./api/routes/authRoutes")(app);
require("./api/routes/userRoutes")(app);
app.listen(port);
console.log("ciucf devotional RESTful API server started on: " + port);
function initial() {
Role.estimatedDocumentCount((err, count) => {
if (!err && count === 0) {
new Role({
name: "user",
}).save((err) => {
if (err) {
console.log("error", err);
}
console.log("added 'user' to roles collection");
});
new Role({
name: "bible-study",
}).save((err) => {
if (err) {
console.log("error", err);
}
console.log("added 'bible-study' to roles collection");
});
new Role({
name: "admin",
}).save((err) => {
if (err) {
console.log("error", err);
}
console.log("added 'admin' to roles collection");
});
}
});
}