I got a website hosted on a Heroku server (i'm a new to Heroku btw), and as it's under the free package, it sleeps after 30m of inactivity, and to put it in action again when a user hits it, it takes around 7 secs to npm run start
successfully.
I'm thinking of run a nodejs job or something that open the website every 29m so that the server never sleeps, initially, I got something like this:
(function wakeup() {
require('open')('https://mywebsite.herokuapp.com', (err) => {
if (err) throw err;
console.log('Woke up!');
setTimeout(wakeup, 1740000); //29m
});
})()
N.B.: That just opens it in a browser, but not handling closing it.
- First, is it legal to do this workaround?
- Second, if yes, what's the best approach to implement this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…