-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler.js
More file actions
60 lines (49 loc) · 1.65 KB
/
Copy pathhandler.js
File metadata and controls
60 lines (49 loc) · 1.65 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
53
54
55
56
57
58
59
60
const serverless = require("serverless-http");
const express = require("express");
const cors = require("cors");
const swaggerJsdoc = require("swagger-jsdoc");
const swaggerUi = require("swagger-ui-express");
const swaggerOptions = require("./swagger");
const authRoutes = require("./src/routes/authRouter");
const workshopRoutes = require("./src/routes/workshopRoutes");
const quizRoutes = require("./src/routes/quizRoutes");
const webinarRoutes = require("./src/routes/webinarRoutes");
const ventureClashRoutes = require("./src/routes/ventureClashRoutes");
require("./db");
// Allowed domains
const allowedOrigins = ["http://localhost:5173", "https://produx.bitesys.org"];
// CORS Configuration
const corsOptions = {
origin: function (origin, callback) {
if (!origin || allowedOrigins.includes(origin)) {
callback(null, true);
} else {
callback(new Error("Not allowed by CORS"));
}
},
credentials: true, // Allow cookies and auth headers
};
// Initialise express app
const app = express();
app.use(cors(corsOptions));
app.use(express.json());
// Add swagger docs
const swaggerSpec = swaggerJsdoc(swaggerOptions);
app.use("/api/docs", swaggerUi.serve, swaggerUi.setup(swaggerSpec));
// Register routes
app.use("/api/auth", authRoutes);
app.use("/api/workshop", workshopRoutes);
app.use("/api/quiz", quizRoutes);
app.use("/api/webinar", webinarRoutes);
app.use("/api/ventureclash", ventureClashRoutes);
// Add Health API
app.get("/health", (req, res) => {
return res.status(200).send("AoK");
});
// Default not found route
app.use((req, res) => {
return res.status(404).json({
error: "Not Found",
});
});
exports.handler = serverless(app);