-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
85 lines (70 loc) · 2.65 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
const status = require("express-status-monitor");
const express = require("express");
const cors = require("cors");
const dotenv = require("dotenv");
const path = require("path");
const databaseConnection = require("./config/database");
const UserRouter = require("./routes/user.route");
const AuthRouter = require("./routes/auth.route");
const ServiceRouter = require("./routes/service.route");
const AppointmentRouter = require("./routes/appointment.route");
const ChatRouter = require("./routes/chat.route");
const NoteRouter = require("./routes/note.route");
const PaymentRouter = require("./routes/payment.route");
const ReviewRouter = require("./routes/review.route");
const termsOfServiceRouter = require("./routes/termsOfService.route");
const faqRouter = require("./routes/faq.route");
const prescriptionRouter = require("./routes/prescription.route");
const tipRouter = require("./routes/tip.route");
const notificationRouter = require("./routes/notification.route");
const helpRouter = require("./routes/help.route");
const aboutUsRouter = require("./routes/aboutUs.route");
const app = express();
dotenv.config();
// const corsOptions = {
// origin: "http://localhost:5173",
// credentials: true,
// };
// app.use(cors(corsOptions));
app.use(cors({ origin: "*" }));
app.use(express.json()); // Parses data as JSON
app.use(express.text()); // Parses data as text
app.use(express.urlencoded({ extended: true })); // Parses data as urlencoded
// checks invalid json file
app.use((err, req, res, next) => {
if (err instanceof SyntaxError && err.status === 400 && "body" in err) {
return res.status(400).send({ message: "invalid json file" });
}
next();
});
const PORT = 3000;
app.use(status());
app.use("/public", express.static(path.join(__dirname, "public")));
app.use("/users", UserRouter);
app.use("/users", AuthRouter);
app.use("/service", ServiceRouter);
app.use("/appointment", AppointmentRouter);
app.use("/payment", PaymentRouter);
app.use("/note", NoteRouter);
app.use("/prescription", prescriptionRouter);
app.use("/chats", ChatRouter);
app.use("/review", ReviewRouter);
app.use("/terms-of-service", termsOfServiceRouter);
app.use("/faq", faqRouter);
app.use("/tip", tipRouter);
app.use("/notification", notificationRouter);
app.use("/help", helpRouter);
app.use("/about-us", aboutUsRouter);
// Route to handle all other invalid requests
app.use((req, res) => {
return res.status(400).send({ message: "Route doesnt exist" });
});
app.use((err, req, res, next) => {
console.error(err);
res.status(500).send({ message: "Internal Server Error" });
});
databaseConnection(() => {
app.listen(PORT, () => {
console.log(`server running on ${PORT}`);
});
});