-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
42 lines (28 loc) · 1.21 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
const express = require('express');
const path = require('path');
const bodyParser = require('body-parser');
var dbquery = require('./dbquery');
var sendemail = require('./sendemail');
var sendsms = require('./sendsms');
const app = express()
const port = process.env.PORT || 3000;
const uri = process.env.MONGO_URL || 'mongodb://127.0.0.1:27017/GoVo';
app.use(bodyParser.json()); // support json encoded bodies
app.use(bodyParser.urlencoded({ extended: true })); // support encoded bodies
//Database connectivity
var mongoose = require('mongoose');
mongoose.set('useCreateIndex', true);
mongoose.connect(uri, { useUnifiedTopology: true, useNewUrlParser: true, useCreateIndex: true });
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function () {
console.log('Database is connected');
});
app.post('/CheckIn', dbquery.CheckIn);
app.post('/CheckOut', dbquery.CheckOut);
app.post('/AddHost', dbquery.AddHost);
app.get('/HostList', dbquery.HostList);
app.post('/sendemail', sendemail.SendEmail);
app.post('/sendsms', sendsms.SendSms);
app.use(express.static(path.join(__dirname, 'public')));
app.listen(port, () => console.log(`App listening on port ${port}!`))