-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
64 lines (52 loc) · 1.48 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
56
57
58
59
60
61
62
63
64
const express = require('express');
const path = require('path');
const mongoose = require('mongoose');
const errorHandler = require('./middlewares/error');
const app = express();
// Configure .env
require('dotenv').config();
// Database setup
let dbAddress = process.env.mongoString;
if (process.env.NODE_ENV === 'production')
dbAddress = process.env.mongoStringProd;
mongoose.connect(
dbAddress,
{
useNewUrlParser: true,
useCreateIndex: true,
useFindAndModify: false,
useUnifiedTopology: true,
},
() => console.log('connected to database!')
);
// Express set up
app.use(require('cors')());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
// Static Files
app.use(express.static('uploads'));
app.get('/bingo', async (req, res, next) => {
const Team = require('./models/team');
const teams = await Team.find();
for (let t of teams) {
if (t.payment_transition_id) {
t.payment_status = 'Paid';
} else {
t.payment_status = 'Not Paid Yet';
}
await t.save();
}
return res.json({ success: true });
});
app.use('/api/v1', require('./index.route'));
if (process.env.NODE_ENV === 'production') {
app.use(express.static(path.join(__dirname, '/client/build')));
app.get('*', (req, res) => {
return res.sendFile(
path.resolve(__dirname, 'client', 'build', 'index.html')
);
});
}
app.use(errorHandler);
const PORT = process.env.PORT;
app.listen(PORT, console.log(`server is running at port: ${PORT}`));