From 292d4bf740ec2e84876d9f36d24507a979a7972a Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Fri, 12 Feb 2016 21:38:04 -0500 Subject: [PATCH] updated example --- README.md | 83 +++++++++++++++++++++++++++---------------------------- 1 file changed, 41 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index 852b4d9..dba03ac 100644 --- a/README.md +++ b/README.md @@ -125,6 +125,47 @@ 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(''); +})).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 ```javascript @@ -163,48 +204,6 @@ console.log(results.plainServers); console.log(results.tlsServers); ``` -### Use with raw http / https modules - -Let's say you want to redirect all http to https. - -``` -var http = require('http'); -var https = require('https'); -var LEX = require('letsencrypt-express'); - -var lex = LEX.create({ - configDir: __dirname + '/letsencrypt.config' -, approveRegistration: function (hostname, cb) { - cb(null, { - domains: [hostname] - , email: 'user@example.com' - , agreeTos: true - }); - } -}); - - -http.createServer(LEX.createAcmeResponder(lex, function redirectHttps(req, res) { - res.setHeader('Location', 'https://' + req.headers.host + req.url); - res.end(''); -})); - - -var app = require('express')(); - -app.use('/', function (req, res) { - res.end('Hello!'); -}); - -https.createServer(lex.httpsOptions, LEX.createAcmeResponder(lex, app)); -``` - -In short these are the only functions you need to be aware of: - -* `LEX.create(opts)` - * `{ configDir: pathname, approveRegistration: func }` -* `LEX.createAcmeResponder(lex, onRequest)` - ### WebSockets with Let's Encrypt Note: you don't need to create websockets for the plain ports.