-
Notifications
You must be signed in to change notification settings - Fork 8
/
server.js
53 lines (40 loc) · 1.31 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
"use strict";
require('dotenv').config();
const PORT = process.env.PORT || 6502
const TEST = (process.argv.indexOf("test") > -1)
const express = require('express');
const https = require("https");
const fs = require("fs");
const cert_path = "./certs/";
const Feed = TEST ? require("./test").Feed : require('./hashtag');
// add timestamps in front of log messages
require( 'console-stamp' )( console, { pattern: 'dd/mm/yyyy HH:MM:ss '},"Serv:" );
function log(l){console.log(l)}
var tootFeed = new Feed();
var app = express();
var emulators = 0;
var served = 0;
app.get('/pop', (req, res) => {
if (req.client.authorized) {
let toot = (tootFeed.queue.length>0) ? tootFeed.queue.pop() : "{}";
res.send(toot);
}
})
app.get('/quit', (req, res) => {
if (req.client.authorized) {
process.exit();
}
})
var options = {
key: fs.readFileSync(cert_path+'server_key.pem'),
cert: fs.readFileSync(cert_path+'server_cert.pem'),
ca: [ fs.readFileSync(cert_path+'server_cert.pem') ],
requestCert: true,
rejectUnauthorized: true
};
var listener = https.createServer(options, app).listen(PORT, function () {
console.log('BBC Micro Bot toot server listening on port ' + listener.address().port);
});
// Poll the twitter mentions
tootFeed.update();
setInterval(function(){ tootFeed.update(); }, 45000);