update for v2.x

This commit is contained in:
AJ ONeal 2016-08-16 14:58:02 -06:00 committed by GitHub
parent aec233397e
commit 24f4bbf6ea
1 changed files with 21 additions and 18 deletions

View File

@ -3,6 +3,7 @@
| [letsencrypt (library)](https://github.com/Daplie/node-letsencrypt) | [letsencrypt (library)](https://github.com/Daplie/node-letsencrypt)
| [letsencrypt-cli](https://github.com/Daplie/letsencrypt-cli) | [letsencrypt-cli](https://github.com/Daplie/letsencrypt-cli)
| [letsencrypt-express](https://github.com/Daplie/letsencrypt-express) | [letsencrypt-express](https://github.com/Daplie/letsencrypt-express)
| [letsencrypt-cluster](https://github.com/Daplie/letsencrypt-cluster)
| **letsencrypt-koa** | **letsencrypt-koa**
| [letsencrypt-hapi](https://github.com/Daplie/letsencrypt-hapi) | [letsencrypt-hapi](https://github.com/Daplie/letsencrypt-hapi)
| |
@ -22,7 +23,7 @@ All you have to do is start the webserver and then visit it at it's domain name.
## Install ## Install
``` ```
npm install --save letsencrypt-express@1.x npm install --save letsencrypt-express@2.x
``` ```
*Pay no attention to the man behind the curtain.* (just ignore that the name of the module is letsencrypt-express) *Pay no attention to the man behind the curtain.* (just ignore that the name of the module is letsencrypt-express)
@ -32,20 +33,20 @@ npm install --save letsencrypt-express@1.x
```javascript ```javascript
'use strict'; 'use strict';
/* Note: using staging server url, remove .testing() for production var le = require('letsencrypt-express').create({
Using .testing() will overwrite the debug flag with true */ server: 'staging' // in production use 'https://acme-v01.api.letsencrypt.org/directory'
var LEX = require('letsencrypt-express').testing();
, configDir: require('os').homedir() + '/letsencrypt/etc'
var lex = LEX.create({ , approveDomains: function (opts, certs, cb) {
configDir: require('os').homedir() + '/letsencrypt/etc' opts.domains = certs && certs.altnames || opts.domains;
, approveRegistration: function (hostname, cb) { // leave `null` to disable automatic registration opts.email = 'john.doe@example.com' // CHANGE ME
// Note: this is the place to check your database to get the user associated with this domain opts.agreeTos = true;
cb(null, {
domains: [hostname] cb(null, { options: opts, certs: certs });
, email: 'CHANGE_ME' // user@example.com
, agreeTos: true
});
} }
, debug: true
}); });
``` ```
@ -55,6 +56,7 @@ WARNING: If you don't do any checks and simply complete `approveRegistration` ca
npm install -g letsencrypt-cli npm install -g letsencrypt-cli
letsencrypt certonly --standalone \ letsencrypt certonly --standalone \
--server 'https://acme-v01.api.letsencrypt.org/directory' \
--config-dir ~/letsencrypt/etc \ --config-dir ~/letsencrypt/etc \
--agree-tos --domains example.com --email user@example.com --agree-tos --domains example.com --email user@example.com
@ -68,20 +70,21 @@ var http = require('http');
var https = require('spdy'); var https = require('spdy');
var koa = require('koa'); var koa = require('koa');
var app = koa(); var app = koa();
var redirectHttps = koa().use(require('koa-sslify')()).callback();
app.use(function *() { app.use(function *() {
this.body = 'Hello World'; this.body = 'Hello World';
}); });
var server = https.createServer(lex.httpsOptions, LEX.createAcmeResponder(lex, app.callback())); var server = https.createServer(le.httpsOptions, le.middleware(app.callback()));
var redirectServer = http.createServer(LEX.createAcmeResponder(lex, redirectHttps)));
server.listen(443, function () { server.listen(443, function () {
console.log('Listening at https://localhost:' + this.address().port); console.log('Listening at https://localhost:' + this.address().port);
}); });
redirectServer.listen(80, function () {
console.log('Redirecting insecure traffic from http://localhost:' + this.address().port + ' to https'); var http = require('http');
var redirectHttps = koa().use(require('koa-sslify')()).callback();
http.createServer(le.middleware(redirectHttps)).listen(80, function () {
console.log('handle ACME http-01 challenge and redirect to https');
}); });
``` ```