-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
32 lines (26 loc) · 769 Bytes
/
Copy pathindex.js
File metadata and controls
32 lines (26 loc) · 769 Bytes
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
import express from 'express';
import cors from 'cors';
import 'dotenv/config';
import './db.js';
import { authRouter, eventsRouter } from './routes/index.js';
const { PORT, FRONTEND, WHITE_LIST } = process.env;
const app = express();
const whiteList = WHITE_LIST?.split(',');
const corsOptions = {
origin: function (origin, callback) {
if (whiteList.indexOf(origin) !== -1 || !origin) {
callback(null, true);
} else {
callback(new Error('Not Allowed by CORS'));
}
}
};
app.use(cors(corsOptions));
app.use(express.json());
// Routes
app.get('/', (_, res) => res.redirect(FRONTEND));
// auth
app.use('/api/auth', authRouter);
// events
app.use('/api/events', eventsRouter);
app.listen(PORT, () => console.log('Server on port:', PORT));