-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathserver.js
51 lines (40 loc) · 1.58 KB
/
server.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
'use strict';
// May eventually replace with a nginx front end built with LE support:
// - https://github.com/JrCs/docker-letsencrypt-nginx-proxy-companion
var path = require('path');
var config = require('./config').ssl;
var app = require('./app')(config.redirect);
console.log(JSON.stringify(config));
// Reference: https://letsencrypt.org/ AND https://github.com/Daplie/letsencrypt-express
if (config.enabled) {
var LEX = require('letsencrypt-express');
var certsDir = path.resolve(config.certsDir, config.prod ? 'prod' : 'staging');
if (!config.prod) {
// Creates "fake" SSL certificates that work ok but will fail CA root cert validation.
// Uses LE staging server to avoid 5 certs/week/domain rate limit (letsencrypt.org/docs/rate-limits/)
LEX = LEX.testing();
}
// Every hour (3600 seconds) the certificates are checked and every certificate
// that will expire in the next 30 days (90 days / 3) are auto-renewed.
var lex = LEX.create({
configDir: certsDir,
onRequest: app,
approveRegistration: function (hostname, approve) { // leave `null` to disable automatic registration
if (config.domains.indexOf(hostname) > -1) { // Or check a database or list of allowed domains
approve(null, {
domains: config.domains,
email: config.email,
agreeTos: true
});
}
}
});
lex.listen(config.plainPorts, config.tlsPorts);
} else {
// Unsecured ports only
config.plainPorts.forEach(function(port) {
app.listen(port, function () {
console.log('Hello app listening on port: ' + port);
});
});
}