-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
51 lines (33 loc) · 1.18 KB
/
index.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
var express = require('express');
var app = express();
var http = require("http");
var schedule = require('node-schedule');
var postToInstagram = require('./methods/postToInstagram.js');
var googleAPI = require("./methods/googleSpreadAPI.js");
var config = require('./config.js');
var j;
app.set('port', (process.env.PORT || 5000));
app.use(express.static(__dirname + '/public'));
app.get('/', function(request, response) {
response.sendFile('index.html');
});
app.get('/api/post-now', function(request, response) {
postToInstagram(j).then(function(res) {
response.send(res);
});
});
app.get('/api/next-post', function(request, response) {
response.send(j.nextInvocation());
});
app.listen(app.get('port'), function() {
console.log('Node app is running on port', app.get('port'));
var postInterval = process.env.POST_INTERVAL || config.POST_INTERVAL;
j = schedule.scheduleJob(postInterval, function() {
postToInstagram(j);
});
console.log('First post will be done at: ' + j.nextInvocation());
setInterval(function() {
console.log('keep alive');
http.get(config.HEROKU_URL);
}, 300000); // every 5 minutes (300000)
});