From b34ad0d59780df08171b031f682a6634e77ffd4b Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Mon, 15 Feb 2016 10:50:07 -0700 Subject: [PATCH] Update README.md --- README.md | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 60e9ce1..b9f216e 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,10 @@ Let's say you want to redirect all http to https. ```javascript var LEX = require('letsencrypt-express'); +var http = require('http'); +var https = require('http2'); +// NOTE: you could use the old https module if for some reason you don't want to support modern browsers + var lex = LEX.create({ configDir: __dirname + '/letsencrypt.config' , approveRegistration: function (hostname, cb) { @@ -97,21 +101,25 @@ var lex = LEX.create({ } }); +function redirectHttp() { + http.createServer(LEX.createAcmeResponder(lex, function redirectHttps(req, res) { + res.setHeader('Location', 'https://' + req.headers.host + req.url); + res.end(''); + })).listen(80); +} -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); +function serveHttps() { + var app = require('express')(); + + app.use('/', function (req, res) { + res.end('Hello!'); + }); + + https.createServer(lex.httpsOptions, LEX.createAcmeResponder(lex, app)).listen(443); +} - -var app = require('express')(); -app.use('/', function (req, res) { - res.end('Hello!'); -}); - -var https = require('http2'); -https.createServer(lex.httpsOptions, LEX.createAcmeResponder(lex, app)).listen(443); +redirectHttp(); +serveHttps(); ``` In short these are the only functions you need to be aware of: