-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
60 lines (43 loc) · 1.52 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
/* jshint esversion:6, node: true */
/* Whobot Server
* https://whobot.herokuapp.com/
*
* © 2017 Jay Schwane & Peter Martinson
*/
/* ================================= SETUP ================================= */
const express = require('express'),
app = express(),
port = process.env.PORT || 3000,
// middleware
bodyParser = require('body-parser'),
morgan = require('morgan'),
// db
db = require('./db'),
mongoose = require('mongoose'),
// whobot
whobot = require('./bin/whobot'),
// Slack auth
slack = require('./slack');
/* ============================== MIDDLEWARE =============================== */
// logging
app.use(morgan('dev'));
// parse POST request body
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
// error handler
app.use(function (err, req, res, next) {
console.log('Error: ', err.stack);
res.status(500).send('Something broke...');
});
/* ============================= CONNECT TO DB ============================= */
mongoose.connect(db.getDbConnectionString());
mongoose.Promise = global.Promise;
/* ================================ ROUTES ================================= */
// Slack authentication route
app.get('/auth', slack);
// bot route
app.post('/whobot', whobot);
/* ============================= START SERVER ============================== */
app.listen(port, function () {
console.log('Whobot server listening on port: ' + port);
});