-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
31 lines (26 loc) · 950 Bytes
/
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
const express = require('express')
const slackEvents = require('./slack/events')
const slackInteractives = require('./slack/interactive')
const normalizePort = require('normalize-port')
const config = require('./config')
// mongodb
const mongoose = require('mongoose')
// database setup
mongoose.Promise = global.Promise
mongoose.connect(config.DB_URL, { useUnifiedTopology: true, useNewUrlParser: true }, (err) => {
if (err) {
console.error('Error occurred while connecting to DB: ', err)
} else {
console.log('DB connection established successfully')
}
})
// express
const port = normalizePort(config.PORT);
const app = express()
app.use('/slack/events', slackEvents.expressMiddleware())
app.use('/slack/actions', slackInteractives.expressMiddleware())
app.use(express.json())
app.use(express.urlencoded({ extended: false }))
app.listen(port, () => {
console.log(`Slack server is listening on port ${port}`)
})