-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.ts
More file actions
49 lines (38 loc) · 1.17 KB
/
app.ts
File metadata and controls
49 lines (38 loc) · 1.17 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
import express from "express";
import cors from "cors";
import userRoutes from './routes/user_route';
import authRoutes from './routes/auth_routes';
import eventRoutes from './routes/event_routes';
import bingoRoutes from './routes/bingo_routes';
import participantConnectionRoutes from "./routes/participant_connections_routes";
const app = express();
app.use(express.json());
const allowedOrigins = process.env.CORS_ORIGINS
? process.env.CORS_ORIGINS.split(",").map((o) => o.trim())
: [];
app.use(
cors({
origin: (origin, callback) => {
if (!origin) {
return callback(null, true);
}
if (allowedOrigins.length === 0) {
return callback(null, true);
}
if (allowedOrigins.includes(origin)) {
return callback(null, true);
}
return callback(new Error(`CORS blocked origin: ${origin}`));
},
credentials: true,
}),
);
app.get("/", (_req, res) => {
res.send("Hello");
});
app.use('/api/users', userRoutes);
app.use('/api/auth', authRoutes);
app.use('/api/events', eventRoutes);
app.use('/api/bingo', bingoRoutes);
app.use("/api/participantConnections", participantConnectionRoutes);
export default app;