UNPKG

1.28 kBJavaScriptView Raw
1// ============
2// ANDRAO-HTTPS
3// ============
4
5var opts = {
6 domains: []
7 , disable: false
8 , email: 'me@example.com'
9 , testing: false
10 , http_ports: [9000]
11 , https_ports:[9090]
12}
13
14module.exports = function(app, opts_in){
15 // options
16 for(var k in opts_in) opts[k] = opts_in[k];
17 if(opts.domains.constructor !== Array) opts.domains = [opts.domains];
18
19 if(opts.disable) return false;
20
21 // LEX
22 if(opts.testing) var LEX = require('letsencrypt-express').testing();
23 else var LEX = require('letsencrypt-express');
24
25 LEX.create({
26 configDir: require('os').homedir() + '/letsencrypt/etc'
27 , onRequest: app
28 , approveRegistration: function (hostname, approve) { // leave `null` to disable automatic registration
29 if (opts.domains.indexOf(hostname) > -1) { // Or check a database or list of allowed domains
30 approve(null, {
31 domains: opts.domains
32 , email: opts.email
33 , agreeTos: true
34 });
35 }
36 }
37 }).listen(opts.http_ports, opts.https_ports, function () {
38 var protocol = ('requestCert' in this) ? 'https': 'http';
39 console.log("Listening at " + protocol + '://localhost:' + this.address().port);
40 });
41}
\No newline at end of file