-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
59 lines (44 loc) · 1.46 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
'use strict'
const path = require('path');
const express = require('express');
var cors = require('cors');
const API_PORT = process.env.PORT || 3000;
const router = express.Router();
const app = express();
var http = require('http').Server(app);
const mongoose = require('mongoose');
let bodyParser = require('body-parser');
// const tribes = require("./routes/Tribes");
// const forms = require("./routes/Forms")
// const Tribes = require('./models/Tribes');
// const Forms = require('./models/Forms');
app.use(cors());
// app.options('*', cors());
app.set('trust proxy', true);
app.use(bodyParser.json({limit: '50mb', extended: true}))
app.use('/api', router);
// app.use('/api/accounts', tribes);
// app.use('/api/forms', forms);
const dbRoute = require('./config/keys').mongoURI;
try{
mongoose.connect(dbRoute, {
useNewUrlParser: true ,
useUnifiedTopology: true,
useFindAndModify: false
});
let db = mongoose.connection;
db.once('open', () => console.log('connected to the database'));
db.on('error', console.error.bind(console, 'MongoDB connection error:'));
}
catch(err){
}
router.get('/',(req,res)=>{
res.send({response:"i am alive"}).status(200);
})
app.use(express.static(path.join(__dirname, 'client/build')));
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'));
});
var server = http.listen(API_PORT, () => {
console.log('server is running on port', server.address().port);
});