-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
61 lines (49 loc) · 1.69 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
50
51
52
53
54
55
56
57
58
59
60
61
'use strict'
const fs = require('fs');
const https = require('https');
const express = require('express');
const bodyParser = require('body-parser');
const schedule = require('node-schedule');
const app = express();
const interaction = require('./bot/interaction.js');
const postservice = require('./bot/postservice.js');
const imageservice = require('./bot/imageservice.js');
const conf = require('./secrets/conf.js');
app.use(bodyParser.json());
app.set('port',(process.env.PORT || conf.PORT));
//setup letsencrypt
var SSL_CONF = {
key : fs.readFileSync(conf.SSL.KEY),
cert : fs.readFileSync(conf.SSL.CERT),
ca : fs.readFileSync(conf.SSL.CA)
};
function startServer() {
https.createServer(SSL_CONF, app).listen(app.get('port'), function (){
console.log('Server running.');
});
app.get('/',function(req, res){
res.send('The Same Photo of Michael Christie Every Day');
});
app.get('/image', function(req, res){
console.log("Image Requested");
res.sendFile(imageservice.getImageFilepath());
imageservice.deleteImage(imageservice.getImageFilepath());
});
app.get('/privacypolicy', function(req, res){
res.sendFile(conf.PRIVACY_POLICY_FILEPATH);
});
app.get('/webhook', interaction.initializeHook);
app.post('/webhook', interaction.handleMessage);
}
console.log("Initializing post service...");
postservice.initializeQueue(function() {
console.log("Starting Scheduling Service.");
var rule = new schedule.RecurrenceRule();
rule.hour = conf.POST_TIME.HOUR;
rule.minute = conf.POST_TIME.MINUTE;
var postschedule = schedule.scheduleJob(rule, function(){
postservice.makePost();
});
console.log("Post Scheduling Service Started.");
startServer();
});