sudo apt install letsencrypt
const express = require('express'),
app = express();
app.use(express.static(path.join(__dirname, 'static')));
app.get('/', (req, res) => res.send("I'm ALIVE!"));
app.listen(80);
certbot --webroot -w ./static -d {{YOUR DOMAIN}}
/etc/letsencrypt/live
function ensureSecure(req, res, next) {
if (req.secure) {
return next();
}
res.redirect('https://' + req.hostname + req.url);
}
app.use(express.static(path.join(__dirname, 'static')));
app.all('*', ensureSecure);
app.listen(80);
const options = {
cert: fs.readFileSync('/etc/letsencrypt/live/{{DOMAIN}}/fullchain.pem'),
key: fs.readFileSync('/etc/letsencrypt/live/{{DOMAIN}}/privkey.pem')
};
https.createServer(options, app).listen(443);
crontab -e
0 10 * * * /usr/bin/certbot renew && /usr/bin/node /usr/local/bin/pm2 restart serve-scriptscront