-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
90 lines (81 loc) · 3.08 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
const bodyParser = require("body-parser");
const cors = require("cors");
const express = require("express");
const mongoose = require("mongoose");
const morgan = require("morgan");
const cron = require("node-cron");
const path = require("path");
const { allCronJobs } = require("./helpers/cronJobs.helper");
const { DATABASE_URI, environment } = require("./config");
const loginRouter = require("./routes/login");
const signUpRouter = require("./routes/signup");
const roommateRouter = require("./routes/roommates");
const listingRouter = require("./routes/listing");
const questionnaireRouter = require("./routes/questionnaire");
const reservationRouter = require("./routes/reservation");
const paymentRouter = require("./routes/payment");
const payoutsRouter = require("./routes/payout.js");
const userRouter = require("./routes/user");
const accountVerificationRouter = require("./routes/accountVerification");
const reviewRouter = require("./routes/reviews");
const subscribeRouter = require("./routes/subscribe");
const contactRouter = require("./routes/contact");
const googleLoginRouter = require("./routes/googleLogin");
const exportsRouter = require("./routes/exports.js");
const adminVerifyRouter = require("./routes/adminVerification");
const containerRouter = require("./routes/container");
const pingRouter = require("./routes/ping");
const housekeepingRouter = require("./routes/housekeeping");
const app = express();
app.use(bodyParser.json());
app.use(cors({ origin: true }));
app.use(morgan("dev"));
app.use("/contact", contactRouter);
app.use("/login", loginRouter);
app.use("/signup", signUpRouter);
app.use("/roommates", roommateRouter);
app.use("/listings", listingRouter);
app.use("/questionnaire", questionnaireRouter);
app.use("/reservation", reservationRouter);
app.use("/payment", paymentRouter);
app.use("/payouts", payoutsRouter);
app.use("/user", userRouter);
app.use("/accountVerification", accountVerificationRouter);
app.use("/reviews", reviewRouter);
app.use("/subscribe", subscribeRouter);
app.use("/contact", contactRouter);
app.use("/googleLogin", googleLoginRouter);
app.use("/exports", exportsRouter);
app.use("/adminVerify", adminVerifyRouter);
app.use("/container", containerRouter);
app.use("/ping", pingRouter);
app.use("/housekeeping", housekeepingRouter);
mongoose.connect(DATABASE_URI, {
useCreateIndex: true,
useFindAndModify: false, // flag needed to enable findOneAndUpdate
useNewUrlParser: true,
useUnifiedTopology: true,
});
if (process.env.NODE_ENV === "production") {
app.use(express.static("assets/"));
app.get("*", (_, res) => {
res.sendFile(path.resolve(__dirname, "assets", "index.html"));
});
}
app.get("/", async (req, res) => {
res.status(200).json("Server is running!");
});
// error handler\
app.use((err, req, res, next) => {
console.log(err);
const isProduction = environment === "production";
res.status(err.status || 500).json({
title: err.title || "Server Error",
errors: err.errors,
stack: isProduction ? null : err.stack,
});
});
cron.schedule("0 8 * * *", allCronJobs, {
timezone: "America/Los_Angeles",
});
module.exports = app;