-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathserver.js
32 lines (28 loc) · 995 Bytes
/
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
require('dotenv').load();
const express = require('express');
const app = express();
const server = require('http').Server(app);
const bodyParser = require('body-parser');
const inspect = require('eyes').inspector({ maxLength: 12048 });
const Slack = require('./Slack');
const port = process.env.PORT || 8080;
const stackexchange = require('stackexchange');
app.use(express.static(__dirname));
app.use(bodyParser.json({ limit: '50mb' }));
app.get('/overflow', function(request, response) {
const options = { version: 2.2 };
const context = new stackexchange(options);
const filter = {
key: process.env.STACK_EXCHANGE_API_KEY,
pagesize: 10,
sort: 'activity',
order: 'asc',
q: request.query.text
};
const slacker = new Slack(request.query.channel_id);
context.search.advanced(filter, function(err, results) {
if (err) throw err;
slacker.postMessage(request.query.text, results);
});
});
server.listen(port, () => inspect(port, 'Server started on '));