-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathheroku.js
46 lines (40 loc) · 1.15 KB
/
heroku.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
require('dotenv').config() // Load .env file
const express = require("express");
const fetch = require("node-fetch");
const wakeUpDyno = (url, interval = 25, callback) => {
const milliseconds = interval * 60000;
setTimeout(() => {
try {
console.log("setTimeout called.");
fetch(url).then(() => console.log(`Fetching ${url}.`));
}
catch (err) {
console.log(`Error fetching ${url}: ${err.message}
Will try again in ${interval} minutes...`);
}
finally {
try {
callback();
}
catch (e) {
callback ? console.log("Callback failed: ", e.message) : null;
}
finally {
return wakeUpDyno(url, interval, callback);
}
}
}, milliseconds);
};
const HEROKU_PORT = process.env.PORT;
const HEROKU_DYNO_URL = process.env.HEROKU_DYNO_URL;
console.log("Heroku port: " + HEROKU_PORT);
console.log("Heroku dyno URL: " + HEROKU_DYNO_URL);
const app = express();
module.exports = function enable_heroku() {
app.get("/", function (req, res) {
res.send("Hello world! you have reached the secret inner workings of the FILC BOT");
});
app.listen(HEROKU_PORT, () => {
wakeUpDyno(HEROKU_DYNO_URL); // will start once server starts
})
}