-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
48 lines (35 loc) · 1.31 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
import express from "express";
import bodyParser from "body-parser";
import cookieParser from "cookie-parser";
import authRoutes from "./routes/auth.js";
import researchGroupRoutes from "./routes/ResearchGropRoutes.js";
import studentRoutes from "./routes/StudentRoutes.js";
import adminRoutes from "./routes/AdminRoutes.js";
import acedemicStaffRoutes from "./routes/AcademicStaffRoutes.js";
import chatRoutes from './routes/ChatRoutes.js';
const app = express();
app.use(bodyParser.json());
app.use(cookieParser());
app.use((req, res, next) => {
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept, Authorization"
);
res.setHeader("Access-Control-Allow-Methods", "GET, POST, PATCH, DELETE");
next();
});
app.use("/api/auth", authRoutes);
app.use("/api/researchGroup", researchGroupRoutes);
app.use("/api/student", studentRoutes);
app.use("/api/admin", adminRoutes);
app.use("/api/acedemicStaff", acedemicStaffRoutes);
app.use("/api/chat", chatRoutes);
app.use((error, req, res) => {
console.log(error);
const status = error.statusCode || 500;
const message = error.message;
const data = error.data;
res.status(status).json({ message: message, data: data });
});
export default app;