-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
59 lines (43 loc) · 1.48 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
import express, { json, urlencoded } from "express";
import morgan from "morgan";
import cors from "cors";
import dotenv from "dotenv";
import connectDatabase from "./services/db_connection.js";
import connectCloudinary from "./services/cloudinary_connection.js";
import authRoutes from "./routes/auth_routes.js";
import userRoutes from "./routes/user_routes.js";
import organizationRoutes from "./routes/organization_routes.js";
import eventRoutes from "./routes/event_routes.js";
import adminRoutes from "./routes/admin_routes.js";
dotenv.config();
const port = process.env.PORT || 3000;
const app = express();
app.use(morgan("dev"));
app.use(cors());
app.use(json()); //parse raw json in req body..using instead of body parser
app.use(urlencoded({ extended: true })); //parse req data coming from URL
//connection to db and cloudinary - asynchronous method using then (NR)
connectDatabase();
connectCloudinary();
//home route
// app.use("/", homeRoutes);
//auth routes
app.use("/auth", authRoutes);
//user routes
app.use("/user", userRoutes);
//organization Routes
app.use("/org", organizationRoutes);
//event Routes
app.use("/events", eventRoutes);
//admin Routes
app.use("/admin", adminRoutes);
//favicon for browser
app.get("/favicon.ico", (_, res) => res.status(204));
//404 error handler page
app.use((_, res) => {
res.status(500).json({ message: "404: Page Not Found", state: false });
});
//Server Listens On:
app.listen(port, () => {
console.log(`Server Listening on ${port}`);
});