|
1 | | -const https = require('https') |
2 | 1 | const Express = require('express') |
3 | 2 | const AcmeTLS = require('./lib/acme-tls') |
4 | | - |
5 | 3 | const hostname = require('@small-tech/cross-platform-hostname') |
6 | 4 |
|
7 | 5 | // |
8 | | -// The API I’m eventually aiming for is: |
9 | | -// |
10 | | -// const https = require('@small-tech/https') |
11 | | -// const Express = require('express') |
| 6 | +// Create and configure a basic “Hello, world!” Express app. |
12 | 7 | // |
13 | | -// const app = new Express() |
14 | | -// const server = https.createServer(app) |
| 8 | +const app = Express() |
| 9 | + |
| 10 | +app.get('/', (request, response) => { |
| 11 | + response.writeHeader(200, {'Content-Type': 'text/html'}) |
| 12 | + response.end('<!doctype html><html lang=\'en\'><head><meta charset=\'utf-8\'/><title>Hello, world!</title><style>body{background-color: white; font-family: sans-serif;}</style></head><body><h1>Hello, world!</h1></body></html>') |
| 13 | +}) |
| 14 | + |
15 | 15 | // |
16 | | -// So, basically, to be isomorphic with the built-in https module. |
| 16 | +// Create an HTTPS server with |
17 | 17 | // |
18 | | -// (And you can optionally supply an options object as the first argument, which would include the types of options |
19 | | -// you can see below.) |
20 | 18 |
|
21 | | -const acmeTLS = AcmeTLS.create({ |
| 19 | +const options = { |
22 | 20 | server: 'staging', |
23 | 21 | configDir: `./config/${hostname}`, |
24 | 22 | approvedDomains: [hostname], |
25 | 23 | debug: true |
26 | | -}) |
27 | | - |
28 | | -// Additional options for the server (none yet). |
29 | | -const options = {} |
30 | | - |
31 | | -// Add TLS options from the ACME TLS Certificate to any existing options that |
32 | | -// might have been passed in above. (Currently, this is the SNICallback function.) |
33 | | -Object.assign(options, acmeTLS.tlsOptions) |
34 | | - |
35 | | -// Create an Express app. |
36 | | -const app = Express() |
37 | | - |
38 | | -app.get('/', (request, response) => { |
39 | | - response.writeHeader(200, {'Content-Type': 'text/html'}) |
40 | | - response.end('<!doctype html><html lang=\'en\'><head><meta charset=\'utf-8\'/><title>Hello, world!</title><style>body{background-color: white; font-family: sans-serif;}</style></head><body><h1>Hello, world!</h1></body></html>') |
41 | | -}) |
| 24 | +} |
42 | 25 |
|
43 | | -const server = https.createServer(options, app) |
| 26 | +const server = AcmeTLS.createServer(options, app) |
44 | 27 |
|
45 | 28 | server.listen(443, () => { |
46 | 29 | console.log(' 🎉 Server running on port 443.') |
|
0 commit comments