-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
63 lines (48 loc) · 1.72 KB
/
server.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
const express = require('express');
const cors = require('cors');
const mongoose = require('mongoose');
const path = require('path')
var enforce = require('express-sslify');
const fs = require('fs')
let Opportunity = require('./models/opportunity.model.js');
const app = express();
app.use(enforce.HTTPS({ trustProtoHeader: true }));
const port = process.env.PORT || 5000;
app.use(cors());
app.use(express.json());
var uri = '';
if (process.env.NODE_ENV === 'production') {
uri = process.env.MONGO_URI
}
else {
uri = ""
}
mongoose.connect(uri, { useNewUrlParser: true, useCreateIndex: true, useFindAndModify: false }
);
const connection = mongoose.connection;
connection.once('open', () => {
console.log("MongoDB database connection established successfully");
})
const opportunitiesRouter = require('./routes/opportunities');
const hostsRouter = require('./routes/hosts');
const waitingusersRouter = require('./routes/waitinglist');
const ambassadorsRouter = require('./routes/ambassador');
const userRouter = require('./routes/user');
const dataRouter = require('./routes/data_collection');
const metaTagsRouter = require('./routes/meta_tags');
const reviewRouter = require('./routes/testimonial');
app.use('/', metaTagsRouter);
app.use('/api/opp/', opportunitiesRouter);
app.use('/api/org/', hostsRouter);
app.use('/api/waiting/', waitingusersRouter);
app.use('/api/amb/', ambassadorsRouter);
app.use('/api/user/', userRouter);
app.use('/api/data/', dataRouter);
app.use('/api/review/', reviewRouter);
app.use(express.static('client/build'));
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'));
});
app.listen(port, () => {
console.log(`Server is running on port: ${port}`);
});