-
Notifications
You must be signed in to change notification settings - Fork 5
/
app.js
49 lines (37 loc) · 1.31 KB
/
app.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
require('dotenv').load();
var express = require('express');
var morgan = require('morgan');
var logger = require('./lib/logger');
var bodyParser = require('body-parser');
var slash = require('./routes/slash');
var auth = require('./routes/auth');
require('./adapters/_init');
var SlackTime = require('./lib/slack_time');
if (!process.env.SLACK_CLIENT_ID || !process.env.SLACK_CLIENT_SECRET || !process.env.SLACK_SLASH_TOKEN) {
logger.error('Error: Specify SLACK_CLIENT_ID SLACK_CLIENT_SECRET SLACK_SLASH_TOKEN in environment');
process.exit(1);
}
var app = express();
app.use(morgan('combined', { 'stream': logger.stream }));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use('/slack/receive', slash({
handler: SlackTime,
token: process.env.SLACK_SLASH_TOKEN
}));
app.use('/slack', auth({
clientId: process.env.SLACK_CLIENT_ID,
clientSecret: process.env.SLACK_CLIENT_SECRET,
scopes: SlackTime.requiredOAuthScopes
}));
app.use(express.static('web/build'));
// catch 404 and forward to error handler
app.use(function(req, res, next) {
res.status(404).send("Not Found");
});
// error handlers
app.use(function(err, req, res, next) {
logger.error("Error: " + err + "\n" + err.stack);
res.status(err.status || 500).send("Channel Time crashed :boom:");
});
module.exports = app;