-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
55 lines (41 loc) · 1.4 KB
/
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
44
45
46
47
48
49
50
51
52
53
54
55
const user = require('./routes/user');
const sports = require('./routes/sports');
const event = require('./routes/event');
const pool = require('./utils/sqlConnectionPool');
const emailClient = require('./utils/emailClient');
const notifyUserTask = require('./scheduled-tasks/notifyUsers');
const Sentry = require('@sentry/node');
const morgan = require('morgan')
const config = require('config');
const cron = require('node-cron');
const express = require('express');
const cors = require('cors');
const app = express();
Sentry.init({ dsn: 'https://[email protected]/1330652' });
app.enable('trust proxy');
app.use(Sentry.Handlers.requestHandler());
app.use(morgan('tiny'));
app.use(express.static('public'));
app.use(express.json());
const corsOptions = {
allowedHeaders: ['x-auth-token', 'Content-Type'],
exposedHeaders: ['x-auth-token']
}
app.use(cors(corsOptions));
app.use('/api/user', user);
app.use('/api/sports', sports);
app.use('/api/event', event);
app.use(Sentry.Handlers.errorHandler());
app.use((err, req, res, next) => {
console.log(err);
res.status(500).send('Server Error');
});
const port = config.get('port');
pool.init().then(async () => {
await emailClient.init();
app.listen(port, () => {
console.log(`Server listening on port ${port}...`);
cron.schedule('0 0 10 * * *', notifyUserTask);
console.log('Task scheduled');
})
});