1 |
|
2 |
|
3 |
|
4 |
|
5 | var opts = {
|
6 | domains: []
|
7 | , disable: false
|
8 | , email: 'me@example.com'
|
9 | , testing: false
|
10 | , http_ports: [9000]
|
11 | , https_ports:[9090]
|
12 | }
|
13 |
|
14 | module.exports = function(app, opts_in){
|
15 |
|
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 |
|
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) {
|
29 | if (opts.domains.indexOf(hostname) > -1) {
|
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 |
|
42 | return function(req, res, next){
|
43 | if(!req.secure) return res.redirect('https://' + req.get('host') + req.url);
|
44 | next();
|
45 | }
|
46 | } |
\ | No newline at end of file |