-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
43 lines (33 loc) · 891 Bytes
/
index.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
import cors from 'cors';
import express from 'express';
import dbConnection from './database/config.js';
import authRouter from './routes/auth.js';
import eventsRouter from './routes/events.js';
const app = express();
const PORT = process.env.PORT || 4001;
//#region Database connection
dbConnection();
//#endregion
// CORS
app.use(cors());
// Public directory
app.use(express.static('public'));
// Body parse middleware
app.use(express.json());
//#region Routes
app.use('/api/auth', authRouter);
app.use('/api/events', eventsRouter);
//#endregion
// Healt route
app.get('/health', (req, res) => {
res.json({
ok: true,
msg: 'API is running',
});
});
// Public content route
app.get('*', (req, res) => {
const __dirname = import.meta.dirname;
res.sendFile(__dirname + '/public/index.html');
});
app.listen(PORT, () => console.log(`Server running on port ${PORT}`));