-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
52 lines (46 loc) · 1.59 KB
/
app.js
File metadata and controls
52 lines (46 loc) · 1.59 KB
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
import express from "express";
import {config} from "dotenv";
import cors from "cors";
import cookieParser from "cookie-parser";
import connectedToDb from "./db/db.js";
import UserRouter from "./routes/userRoutes.js";
import QuestionRouter from "./routes/questionRoutes.js";
import TopicRouter from "./routes/topicRoutes.js";
import ChapterRouter from "./routes/chapterRoutes.js"
import SubTopicRouter from "./routes/subtopicRoutes.js";
import SubjectRouter from "./routes/subjectRoutes.js"
import ExtractRouter from "./routes/extractionRoutes.js";
config({
path: "./.env",
});
const app = express();
const port = process.env.PORT || 4005;
connectedToDb();
app.use(express.json());
app.use(cookieParser());
app.use(
cors({
origin: (origin, callback) => {
if (origin === undefined || origin === null) {
callback(null, true);
} else if (
origin.match(/^https?:\/\/(.*\.)?vercel\.app$/) ||
origin === process.env.FRONTEND_URL
) {
callback(null, true);
} else {
console.log('Not allowed by CORS:', origin);
callback(new Error('Not allowed by CORS'));
}
},
methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'],
credentials: true,
})
);
app.use("/api", QuestionRouter, TopicRouter, SubjectRouter, ChapterRouter, SubTopicRouter, ExtractRouter);
app.use("/api/user", UserRouter);
app.get("/", (req, res) => {
res.send("Server is working fine");
});
// export const handler = serverless(app);
app.listen(port, () => console.log(`Server is listening at port ${port}`));