Update README.md

This commit is contained in:
AJ ONeal 2016-02-15 09:12:22 -07:00
parent 379aa84c2a
commit 84f618a056
1 changed files with 40 additions and 41 deletions

View File

@ -80,6 +80,46 @@ and that will cause you to be rate-limited and or blocked from the ACME server)
## Examples ## Examples
### Use with raw http / https modules
Let's say you want to redirect all http to https.
```javascript
var LEX = require('letsencrypt-express');
var lex = LEX.create({
configDir: __dirname + '/letsencrypt.config'
, approveRegistration: function (hostname, cb) {
cb(null, {
domains: [hostname]
, email: 'CHANGE_ME' // 'user@example.com'
, agreeTos: true
});
}
});
var http = require('http');
http.createServer(LEX.createAcmeResponder(lex, function redirectHttps(req, res) {
res.setHeader('Location', 'https://' + req.headers.host + req.url);
res.end('<!-- Hello Developer Person! Please use HTTPS instead -->');
})).listen(80);
var app = require('express')();
app.use('/', function (req, res) {
res.end('Hello!');
});
var https = require('https');
https.createServer(lex.httpsOptions, LEX.createAcmeResponder(lex, app)).listen(443);
```
In short these are the only functions you need to be aware of:
* `LEX.create(opts)`
* `{ configDir: pathname, approveRegistration: func }`
* `LEX.createAcmeResponder(lex, onRequest)`
### < 140 Characters ### < 140 Characters
Let's Encrypt in 128 characters, with spaces! Let's Encrypt in 128 characters, with spaces!
@ -125,47 +165,6 @@ LEX.create({
}); });
``` ```
### Use with raw http / https modules
Let's say you want to redirect all http to https.
```
var LEX = require('letsencrypt-express');
var lex = LEX.create({
configDir: __dirname + '/letsencrypt.config'
, approveRegistration: function (hostname, cb) {
cb(null, {
domains: [hostname]
, email: 'CHANGE_ME' // 'user@example.com'
, agreeTos: true
});
}
});
var http = require('http');
http.createServer(LEX.createAcmeResponder(lex, function redirectHttps(req, res) {
res.setHeader('Location', 'https://' + req.headers.host + req.url);
res.end('<!-- Hello Developer Person! Please use HTTPS instead -->');
})).listen(80);
var app = require('express')();
app.use('/', function (req, res) {
res.end('Hello!');
});
var https = require('https');
https.createServer(lex.httpsOptions, LEX.createAcmeResponder(lex, app)).listen(443);
```
In short these are the only functions you need to be aware of:
* `LEX.create(opts)`
* `{ configDir: pathname, approveRegistration: func }`
* `LEX.createAcmeResponder(lex, onRequest)`
### More Options Exposed ### More Options Exposed
```javascript ```javascript