-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
70 lines (51 loc) · 1.89 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
const express = require("express");
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
const cors = require("cors");
require("dotenv").config();
const {updatePollsRemainingTime} = require("./utils/updateRemainTime");
// Import Routes
const authBuildingRoute = require("./routes/BuildingAccount.AuthOps.Route");
const authUserRoute = require("./routes/UserAccount.AuthOps.Route");
const signInUserRoute = require("./routes/Signin.AuthOps.Route");
const residentControllerRoute = require("./routes/Controllers/resident.controller");
const commentControllerRoute = require("./routes/Controllers/comment.controller");
const pollRoute = require("./routes/Controllers/poll.controller");
const likeControllerRoute = require("./routes/Controllers/like.controller");
//
const app = express();
app.use(express.static("public"));
app.use(cors());
//app.use(bodyParser.json());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
const port = process.env.PORT || 3000;
app.use("/registerBuild", authBuildingRoute);
app.use( authUserRoute);
app.use(residentControllerRoute);
app.use(commentControllerRoute);
app.use(likeControllerRoute);
app.use(signInUserRoute);
app.use(pollRoute);
app.get("/", (req, res) => {
res.send("APP IS RUNNING");
});
//! DB Connection
const mongoUri = process.env.MONGO_URI;
mongoose.connect(mongoUri, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
mongoose.connection.on("connected", () => {
console.log("MongoDB connected");
});
mongoose.connection.on("error", (err) => {
console.error("Error connecting to mongo", err);
});
// Call the function when you start your server
updatePollsRemainingTime();
// Set up a timer to periodically update remaining time (every minute in this example)
setInterval(updatePollsRemainingTime, 60000);
app.listen(port, () => {
console.log(`Server running on port ${port}`);
});