@small-tech/https 3.1.0 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,18 +1,34 @@
1
1
  # @small-tech/https
2
2
 
3
- A drop-in standard Node.js HTTPS module replacement with both automatic development-time (localhost) certificates via Auto Encrypt Localhost and automatic production certificates via Auto Encrypt.
3
+ A batteries-included version of the standard Node.js `https` module.
4
4
 
5
5
  Simply replace Node’s `https` module with `@small-tech/https` and get:
6
6
 
7
- - Automatically-provisioned TLS certificates at localhost with no browser warnings via [mkcert](https://github.com/FiloSottile/mkcert).
8
- - Automatically-provisioned TLS certificates at hostname via [Let’s Encrypt](https://letsencrypt.org/).
9
- - Automatic HTTP to HTTPS forwarding at hostname.
7
+ - Automatically-provisioned trusted local development TLS certificates via [Auto Encrypt Localhost](https://codeberg.org/small-tech/auto-encrypt-localhost)
8
+
9
+ - Automatically-provisioned [Let’s Encrypt](https://letsencrypt.org/) TLS certificates via [Auto Encrypt](https://codeberg.org/small-tech/auto-encrypt).
10
+
11
+ - Automatic HTTP to HTTPS forwarding.
10
12
 
11
13
  That’s it.
12
14
 
13
- This is basically a batteries-included version of the standard Node.js `https` module.
15
+ ___Note:__ This is a standard ECMAScript Modules (ESM; es6 modules) project. If you need to use legacy CommonJS, [please see the 2.x branch](https://github.com/small-tech/https/tree/2.x) which is deprecated but still receives bug fixes._
16
+
17
+ ## System requirements
18
+
19
+ - Version 4.x, 5.x+: Node 18.2 LTS+
20
+ - Version 3.x: Node 16 LTS
21
+ - Version 2.x: CJS, Node 16 LTS
22
+
23
+ __Tested and supported on:__
14
24
 
15
- ___Note:__ This is a standard ECMAScript Modules (ESM; es6 modules) project. If you need to use legacy CommonJS, [please see the 2.x branch](https://github.com/small-tech/https/tree/2.x) which is currently still being maintained._
25
+ - Linux (tested on Fedora Silverblue 37 and Ubuntu 22.04)
26
+ - macOS (tested on Intel: Monterey, M1: Ventura)
27
+ - Windows (10 and 11 under Windows Terminal and with Windows PowerShell)
28
+
29
+ > 💡 On macOS, if you’re using a third-party terminal application like iTerm, you must give it Full Disk Access rights or @small-tech/https will fail to install the policy file inside Firefox when creating local development servers. You can do this on the latest version of the operating system by adding iTerm to the list at System Settings → Privacy & Security → Full Disk Access.
30
+
31
+ > 💡 On Windows, @small-tech/https will also run under WSL 2 but this is not recommended when creating local development servers as local development certificates will not be automatically installed in your Windows browsers for you since your guest Linux system knows nothing about and cannot configure your host Windows environment.
16
32
 
17
33
  ## Like this? Fund us!
18
34
 
@@ -26,27 +42,15 @@ This is [small technology](https://small-tech.org/about/#small-technology).
26
42
 
27
43
  If you’re evaluating this for a “startup” or an enterprise, let us save you some time: this is not the right tool for you. This tool is for individual developers to build personal web sites and apps for themselves and for others in a non-colonial manner that respects the human rights of the people who use them.
28
44
 
29
- ## Platform support
30
-
31
- Tested and supported on:
32
-
33
- - Linux (tested with elementary OS 5.x/Hera)
34
- - macOS (tested on Big Sur)
35
- - Windows 10 (tested in Windows Terminal with PowerShell)
36
-
37
- (WSL is not supported for certificates at localhost unless you’re running your browser under WSL also).
38
-
39
45
  ## Install
40
46
 
41
47
  ```sh
42
48
  npm i @small-tech/https
43
49
  ```
44
50
 
45
- Note that during installation, this module’s Auto Encrypt Localhost dependency will download the correct mkcert binary to your machine.
46
-
47
51
  ## Examples
48
52
 
49
- ### At localhost with automatically-provisioned development certificates via mkcert.
53
+ ### At localhost with automatically-provisioned localhost development certificates.
50
54
 
51
55
  ```js
52
56
  import https from '@small-tech/https'
@@ -62,7 +66,7 @@ server.listen(443, () => {
62
66
 
63
67
  Hit `https://localhost` and you should see your site with locally-trusted TLS certificates.
64
68
 
65
- @small-tech/https uses mkcert to create a local certificate authority and add it to the various trust stores. It then uses it to create locally-trusted TLS certificates that are automatically used by your server.
69
+ @small-tech/https uses [Auto Encrypt Localhost](https://codeberg.org/small-tech/auto-encrypt-localhost) to create a local Certificate Authority (cA) and add it to the various trust stores. It then uses that CA to create locally-trusted TLS certificates that are automatically used by your server.
66
70
 
67
71
  ### At hostname with automatically-provisioned Let’s Encrypt certificates.
68
72
 
@@ -84,7 +88,7 @@ server.listen(443, () => {
84
88
 
85
89
  To provision globally-trusted Let’s Encrypt certificates, we additionally create an `options` object containing the domain(s) we want to support, and pass it as the first argument in the `createServer()` method.
86
90
 
87
- @small-tech/https automatically provisions Let’s Encrypt certificates for you the first time your server is hit (this first load will take longer than future ones). During this initial load, other requests are ignored. This module will also automatically renew your certificates as necessary in plenty of time before they expire.
91
+ @small-tech/https automatically provisions Let’s Encrypt certificates for you the first time your server is hit using [Auto Encrypt](https://codeberg.org/small-tech/auto-encrypt) (this first load will take longer than future ones). During this initial load, other requests are ignored. This module will also automatically renew your certificates as necessary in plenty of time before they expire.
88
92
 
89
93
  You can find a version of this example in the `/example` folder. To download and run that version:
90
94
 
@@ -126,26 +130,36 @@ Lower-level:
126
130
 
127
131
  ### Auto Encrypt
128
132
 
129
- - Source: https://source.small-tech.org/site.js/lib/auto-encrypt
130
- - Package: [@small-tech/auto-encrypt](https://www.npmjs.com/package/@small-tech/auto-encrypt)
133
+ - Source: https://github.com/small-tech/auto-encrypt
134
+ - Package: [@small-tech/auto-encrypt](https://www.npmjs.com/package/@small-tech/auto-encrypt)
131
135
 
132
- Adds automatic provisioning and renewal of [Let’s Encrypt](https://letsencrypt.org) TLS certificates with [OCSP Stapling](https://letsencrypt.org/docs/integration-guide/#implement-ocsp-stapling) to [Node.js](https://nodejs.org) [https](https://nodejs.org/dist/latest-v12.x/docs/api/https.html) servers (including [Express.js](https://expressjs.com/), etc.)
136
+ Adds automatic provisioning and renewal of [Let’s Encrypt](https://letsencrypt.org) TLS certificates with [OCSP Stapling](https://letsencrypt.org/docs/integration-guide/#implement-ocsp-stapling) to [Node.js](https://nodejs.org) [https](https://nodejs.org/dist/latest-v12.x/docs/api/https.html) servers (including Polka, Express.js, etc.)
133
137
 
134
138
  ### Auto Encrypt Localhost
135
139
 
136
- - Source: https://source.small-tech.org/site.js/lib/auto-encrypt-localhost
137
- - Package: [@small-tech/auto-encrypt-localhost](https://www.npmjs.com/package/@small-tech/auto-encrypt-localhost)
140
+ - Source: https://codeberg.org/small-tech/auto-encrypt-localhost
141
+ - Package: [@small-tech/auto-encrypt-localhost](https://www.npmjs.com/package/@small-tech/auto-encrypt-localhost)
138
142
 
139
- Automatically provisions and installs locally-trusted TLS certificates for Node.js https servers (including Express.js, etc.) using [mkcert](https://github.com/FiloSottile/mkcert/).
143
+ Automatically provisions and installs locally-trusted TLS certificates for Node.js https servers (including Polka, Express.js, etc.).
140
144
 
141
145
  Higher level:
142
146
 
143
147
  ### Site.js
144
148
 
145
- - Web site: https://sitejs.org
146
- - Source: https://source.small-tech.org/site.js/app
149
+ - Web site: https://sitejs.org
150
+ - Source: https://github.com/small-tech/site.js
151
+
152
+ A tool for developing, testing, and deploying a secure static or dynamic personal web site or app with zero configuration.
153
+
154
+ Note: **Deprecated.** Site.js is being used to serve a number of our own web sites and isn’t going away anytime soon but all new development work is on Kitten.
155
+
156
+ ### Kitten
157
+
158
+ - Web site/source code: https://codeberg.org/kitten/app
159
+
160
+ A [Small Web](https://small-tech.org/research-and-development/) development kit.
147
161
 
148
- A complete [small technology](https://small-tech.org/about/#small-technology) tool for developing, testing, and deploying a secure static or dynamic personal web site or app with zero configuration.
162
+ Create your Small Web site using plain HTML, CSS, and JavaScript then enhance it with [htmx](https://htmx.org/) and [Alpine.js](https://alpinejs.dev), if you like.
149
163
 
150
164
  ## Copyright
151
165
 
@@ -155,4 +169,4 @@ Let’s Encrypt is a trademark of the Internet Security Research Group (ISRG). A
155
169
 
156
170
  ## License
157
171
 
158
- [AGPL version 3.0 or later.](https://www.gnu.org/licenses/agpl-3.0.en.html)
172
+ [AGPL version 3.0.](https://www.gnu.org/licenses/agpl-3.0.en.html)
package/index.js CHANGED
@@ -1,13 +1,31 @@
1
- import os from 'os'
2
- import fs from 'fs-extra'
3
- import path from 'path'
4
- import https from 'https'
1
+ import os from 'node:os'
2
+ import process from 'node:process'
3
+ import path from 'node:path'
4
+ import https from 'node:https'
5
+ import EventEmitter from 'node:events'
6
+
5
7
  import AutoEncrypt from '@small-tech/auto-encrypt'
6
8
  import AutoEncryptLocalhost from '@small-tech/auto-encrypt-localhost'
7
- import log from './lib/util/log.js'
9
+
10
+ class Events extends EventEmitter {
11
+ CREATING_SERVER = Symbol()
12
+ SERVER_CREATED = Symbol()
13
+ SERVER_CLOSED = Symbol()
14
+ }
15
+
16
+ export const events = new Events()
8
17
 
9
18
  const AUTO_ENCRYPT_STAGING_SERVER_TYPE = 1
10
19
 
20
+ const DATA_HOME = path.join(
21
+ process.env.XDG_DATA_HOME || process.env.HOME || os.homedir(),
22
+ '.local',
23
+ 'share'
24
+ )
25
+
26
+ export const SMALL_TECH_HOME_PATH = path.join(DATA_HOME, 'small-tech.org')
27
+ export const DEFAULT_SETTINGS_PATH = path.join(SMALL_TECH_HOME_PATH, 'https')
28
+
11
29
  // Only modify this instance of the https module with our own createServer method.
12
30
  const smallTechHttps = Object.assign({}, https)
13
31
 
@@ -18,46 +36,43 @@ smallTechHttps.createServer = function (options, listener) {
18
36
  options = {}
19
37
  }
20
38
 
21
- const defaultSettingsPath = path.join(os.homedir(), '.small-tech.org', 'https')
22
39
  const serverScope = options.domains == undefined || options.domains.includes('localhost') ? 'local' : 'global'
23
-
24
- const settingsPath = options.settingsPath ? path.join(path.resolve(options.settingsPath), serverScope) : path.join(defaultSettingsPath, serverScope)
25
-
40
+ const settingsPath = options.settingsPath ? path.join(path.resolve(options.settingsPath), serverScope) : path.join(DEFAULT_SETTINGS_PATH, serverScope)
26
41
  options.settingsPath = settingsPath
27
42
 
28
43
  if (options.staging) { options.serverType = AUTO_ENCRYPT_STAGING_SERVER_TYPE }
29
44
  delete options.staging
30
45
 
31
- const logMessage = {
32
- local: 'at localhost with locally-trusted certificates',
33
- global: 'with globally-trusted Let’s Encrypt certificates'
34
- }
35
-
36
46
  const autoEncryptScope = {
37
47
  local: AutoEncryptLocalhost,
38
48
  global: AutoEncrypt
39
49
  }
40
50
 
41
- log(` 🔒 ❨https❩ Creating server ${logMessage[serverScope]}.`)
51
+ const messageSuffix = {
52
+ local: 'at localhost with locally-trusted certificates',
53
+ global: 'with globally-trusted Let’s Encrypt certificates'
54
+ }
55
+ events.emit(events.CREATING_SERVER, `Creating server ${messageSuffix[serverScope]}.`)
56
+
42
57
  const server = autoEncryptScope[serverScope].https.createServer(options, listener)
43
58
 
44
- if (serverScope === 'global') {
45
- // Migration: 1.1.0 and earlier to 1.2.0+:
46
- // Remove the old Let’s Encrypt client’s certificate settings.
47
- // (And thus force upgrade to certificates managed by Auto Encrypt on first hit of server.)
48
- const oldLetsEncryptSettingsPathFor = directory => path.join(settingsPath, directory)
49
- fs.removeSync(oldLetsEncryptSettingsPathFor('accounts'))
50
- fs.removeSync(oldLetsEncryptSettingsPathFor('archive'))
51
- fs.removeSync(oldLetsEncryptSettingsPathFor('live'))
52
- fs.removeSync(oldLetsEncryptSettingsPathFor('renewal'))
59
+ function emitCloseEvent() {
60
+ events.emit(events.SERVER_CLOSED, 'Server closed.')
61
+ }
53
62
 
63
+ if (serverScope === 'global') {
54
64
  // Allow AutoEncrypt to perform clean-up (e.g., remove interval timer for renewal check, etc.)
55
65
  server.on('close', () => {
56
66
  AutoEncrypt.shutdown()
67
+ emitCloseEvent()
57
68
  })
69
+ } else {
70
+ // No additional clean-up required for Auto Encrypt Localhost.
71
+ server.on('close', emitCloseEvent)
58
72
  }
59
73
 
60
- log(' 🔒 ❨https❩ Created HTTPS server.')
74
+ events.emit(events.SERVER_CREATED, 'Created HTTPS server.')
75
+
61
76
  return server
62
77
  }
63
78
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@small-tech/https",
3
- "version": "3.1.0",
3
+ "version": "5.0.0",
4
4
  "description": "A drop-in standard Node.js HTTPS module replacement with both automatic development-time (localhost) certificates via Auto Encrypt Localhost and automatic production certificates via Auto Encrypt.",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -44,11 +44,10 @@
44
44
  "email": "aral@small-tech.org",
45
45
  "url": "https://ar.al"
46
46
  },
47
- "license": "AGPL-3.0-or-later",
47
+ "license": "AGPL-3.0",
48
48
  "dependencies": {
49
- "@small-tech/auto-encrypt": "^3.1.0",
50
- "@small-tech/auto-encrypt-localhost": "^7.0.7",
51
- "fs-extra": "^9.0.1"
49
+ "@small-tech/auto-encrypt": "^4.0.0",
50
+ "@small-tech/auto-encrypt-localhost": "^8.2.0"
52
51
  },
53
52
  "devDependencies": {
54
53
  "@small-tech/cross-platform-hostname": "^1.0.0",
@@ -56,13 +55,11 @@
56
55
  "@small-tech/tap-monkey": "^1.3.0",
57
56
  "bent": "^7.3.12",
58
57
  "c8": "^7.6.0",
59
- "tape": "^5.2.2",
60
- "wtfnode": "^0.8.1"
58
+ "tape": "^5.2.2"
61
59
  },
62
60
  "nyc": {
63
61
  "exclude": [
64
- "test/**/*.js",
65
- "lib/util/*.js"
62
+ "test/**/*.js"
66
63
  ]
67
64
  }
68
65
  }
package/lib/util/log.js DELETED
@@ -1,6 +0,0 @@
1
- export default function log(...args) {
2
- if (process.env.QUIET) {
3
- return
4
- }
5
- console.log(...args)
6
- }