From a48c10e0829d76ad3edbf54063608bc6378e9173 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Tue, 3 Jul 2018 03:25:12 -0600 Subject: [PATCH] slight simplification of examples --- README.md | 15 +++++++-------- examples/demo.js | 2 +- examples/http2.js | 2 +- examples/my-express-app.js | 15 +++++++++++++++ examples/normal.js | 25 +++++-------------------- examples/remote-access.js | 2 +- examples/simple.js | 2 +- examples/spdy.js | 8 +++----- examples/vhost.js | 2 +- package.json | 3 ++- 10 files changed, 37 insertions(+), 39 deletions(-) create mode 100644 examples/my-express-app.js diff --git a/README.md b/README.md index 61a6c7c..49d2230 100644 --- a/README.md +++ b/README.md @@ -147,30 +147,29 @@ require('greenlock-express').create({ // Let's Encrypt v2 is ACME draft 11 version: 'draft-11' -, server: 'https://acme-v02.api.letsencrypt.org/directory' // Note: If at first you don't succeed, switch to staging to debug // https://acme-staging-v02.api.letsencrypt.org/directory +, server: 'https://acme-v02.api.letsencrypt.org/directory' + + // Where the certs will be saved, MUST have write access +, configDir: '~/.config/acme/' // You MUST change this to a valid email address , email: 'john.doe@example.com' - // You MUST NOT build clients that accept the ToS without asking the user -, agreeTos: true - // You MUST change these to valid domains // NOTE: all domains will validated and listed on the certificate , approveDomains: [ 'example.com', 'www.example.com' ] - // You MUST have access to write to directory where certs are saved - // ex: /home/foouser/acme/etc -, configDir: require('path').join(require('os').homedir(), 'acme', 'etc') + // You MUST NOT build clients that accept the ToS without asking the user +, agreeTos: true , app: require('express')().use('/', function (req, res) { res.setHeader('Content-Type', 'text/html; charset=utf-8') res.end('Hello, World!\n\nšŸ’š šŸ”’.js'); }) - // Join the community to get notified of important updates and help me make greenlock better + // Join the community to get notified of important updates , communityMember: true // Contribute telemetry data to the project diff --git a/examples/demo.js b/examples/demo.js index 4b92c6f..d597667 100644 --- a/examples/demo.js +++ b/examples/demo.js @@ -26,7 +26,7 @@ var greenlock = Greenlock.create({ // You MUST have access to write to directory where certs are saved // ex: /home/foouser/acme/etc -, configDir: require('path').join(require('os').homedir(), 'acme', 'etc') +, configDir: '~/.config/acme/' // Get notified of important updates and help me make greenlock better , communityMember: true diff --git a/examples/http2.js b/examples/http2.js index a25be36..fbfc9fb 100644 --- a/examples/http2.js +++ b/examples/http2.js @@ -24,7 +24,7 @@ var greenlock = Greenlock.create({ // You MUST have access to write to directory where certs are saved // ex: /home/foouser/acme/etc -, configDir: require('path').join(require('os').homedir(), 'acme', 'etc') +, configDir: '~/.config/acme/' // Get notified of important updates and help me make greenlock better , communityMember: true diff --git a/examples/my-express-app.js b/examples/my-express-app.js new file mode 100644 index 0000000..04da098 --- /dev/null +++ b/examples/my-express-app.js @@ -0,0 +1,15 @@ +'use strict'; + +var express = require('express'); +var app = express(); + +app.use('/', function (req, res) { + res.setHeader('Content-Type', 'text/html; charset=utf-8'); + res.end('Hello, World!\n\nšŸ’š šŸ”’.js'); +}); + +// DO NOT DO app.listen() unless we're testing this directly +if (require.main === module) { app.listen(3000); } + +// Instead do export the app: +module.exports = app; diff --git a/examples/normal.js b/examples/normal.js index c4bebb0..c9e1da3 100644 --- a/examples/normal.js +++ b/examples/normal.js @@ -1,17 +1,5 @@ 'use strict'; -// -// My Express App -// -var express = require('express'); -var app = express(); - -app.use('/', function (req, res) { - res.setHeader('Content-Type', 'text/html; charset=utf-8') - res.end('Hello, World!\n\nšŸ’š šŸ”’.js'); -}); - - // // My Secure Server // @@ -19,11 +7,12 @@ app.use('/', function (req, res) { require('../').create({ // Let's Encrypt v2 is ACME draft 11 - version: 'draft-11' - -, server: 'https://acme-v02.api.letsencrypt.org/directory' // Note: If at first you don't succeed, stop and switch to staging // https://acme-staging-v02.api.letsencrypt.org/directory + server: 'https://acme-v02.api.letsencrypt.org/directory' +, version: 'draft-11' + // You MUST have write access to save certs +, configDir: '~/.config/acme/' // The previous 'simple' example set these values statically, // but this example uses approveDomains() to set them dynamically @@ -34,11 +23,7 @@ require('../').create({ // email addresses with domains and agreements and such , approveDomains: approveDomains - // You MUST have access to write to directory where certs are saved - // ex: /etc/greenlock/ -, configDir: '/tmp/etc/greenlock' - -, app: app +, app: require('./my-express-app.js') // Get notified of important updates and help me make greenlock better , communityMember: true diff --git a/examples/remote-access.js b/examples/remote-access.js index 05bad38..87676d6 100644 --- a/examples/remote-access.js +++ b/examples/remote-access.js @@ -25,7 +25,7 @@ require('../').create({ , email: email , agreeTos: agreeLeTos , approveDomains: domains -, configDir: require('path').join(require('os').homedir(), 'acme', 'etc') +, configDir: '~/.config/acme/' , app: remoteAccess(secret) // Get notified of important updates and help me make greenlock better , communityMember: true diff --git a/examples/simple.js b/examples/simple.js index e53cc58..34ab710 100644 --- a/examples/simple.js +++ b/examples/simple.js @@ -22,7 +22,7 @@ require('../').create({ // You MUST have access to write to directory where certs are saved // ex: /home/foouser/acme/etc -, configDir: require('path').join(require('os').homedir(), 'acme', 'etc') +, configDir: '~/.config/acme/' , app: require('express')().use('/', function (req, res) { res.setHeader('Content-Type', 'text/html; charset=utf-8'); diff --git a/examples/spdy.js b/examples/spdy.js index d848221..d9368a9 100644 --- a/examples/spdy.js +++ b/examples/spdy.js @@ -26,7 +26,7 @@ var greenlock = Greenlock.create({ // You MUST have access to write to directory where certs are saved // ex: /home/foouser/acme/etc -, configDir: require('path').join(require('os').homedir(), 'acme', 'etc') +, configDir: '~/.config/acme/' // MUST have write access // Get notified of important updates and help me make greenlock better , communityMember: true @@ -57,10 +57,8 @@ require('http').createServer(acmeChallengeHandler).listen(80, function () { // spdy is a drop-in replacement for the https API var spdyOptions = Object.assign({}, greenlock.tlsOptions); spdyOptions.spdy = { protocols: [ 'h2', 'http/1.1' ], plain: false }; -var server = require('spdy').createServer(spdyOptions, require('express')().use('/', function (req, res) { - res.setHeader('Content-Type', 'text/html; charset=utf-8'); - res.end('Hello, SPDY World!\n\nšŸ’š šŸ”’.js'); -})); +var myApp = require('./my-express-app.js'); +var server = require('spdy').createServer(spdyOptions, myApp); server.on('error', function (err) { console.error(err); }); diff --git a/examples/vhost.js b/examples/vhost.js index 09978cc..624491b 100644 --- a/examples/vhost.js +++ b/examples/vhost.js @@ -69,7 +69,7 @@ require('../').create({ // You MUST have access to write to directory where certs are saved // ex: /home/foouser/acme/etc -, configDir: require('path').join(require('os').homedir(), 'acme', 'etc') +, configDir: '~/.config/acme/' , app: function (req, res) { console.log(req.headers.host); diff --git a/package.json b/package.json index bc67583..f3d9615 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,8 @@ "express-basic-auth": "^1.1.5", "finalhandler": "^1.1.1", "serve-index": "^1.9.1", - "serve-static": "^1.13.2" + "serve-static": "^1.13.2", + "ws": "^5.2.1" }, "scripts": { "test": "node examples/simple.js"