@small-tech/https 4.0.0 → 5.0.1

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,27 +1,35 @@
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)
10
8
 
11
- That’s it.
9
+ - Automatically-provisioned [Let’s Encrypt](https://letsencrypt.org/) TLS certificates via [Auto Encrypt](https://codeberg.org/small-tech/auto-encrypt).
12
10
 
13
- This is basically a batteries-included version of the standard Node.js `https` module.
11
+ - Automatic HTTP to HTTPS forwarding.
14
12
 
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._
13
+ That’s it.
16
14
 
17
- ## Compatibility
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._
18
16
 
19
- - Version 4.x: Node 18.2 LTS+
17
+ ## System requirements
20
18
 
19
+ - Version 4.x, 5.x+: Node 18.2 LTS+
21
20
  - Version 3.x: Node 16 LTS
22
-
23
21
  - Version 2.x: CJS, Node 16 LTS
24
22
 
23
+ __Tested and supported on:__
24
+
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.
32
+
25
33
  ## Like this? Fund us!
26
34
 
27
35
  [Small Technology Foundation](https://small-tech.org) is a tiny, independent not-for-profit.
@@ -34,27 +42,15 @@ This is [small technology](https://small-tech.org/about/#small-technology).
34
42
 
35
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.
36
44
 
37
- ## Platform support
38
-
39
- Tested and supported on:
40
-
41
- - Linux (tested with elementary OS 5.x/Hera)
42
- - macOS (tested on Big Sur)
43
- - Windows 10 (tested in Windows Terminal with PowerShell)
44
-
45
- (WSL is not supported for certificates at localhost unless you’re running your browser under WSL also).
46
-
47
45
  ## Install
48
46
 
49
47
  ```sh
50
48
  npm i @small-tech/https
51
49
  ```
52
50
 
53
- Note that during installation, this module’s Auto Encrypt Localhost dependency will download the correct mkcert binary to your machine.
54
-
55
51
  ## Examples
56
52
 
57
- ### At localhost with automatically-provisioned development certificates via mkcert.
53
+ ### At localhost with automatically-provisioned localhost development certificates.
58
54
 
59
55
  ```js
60
56
  import https from '@small-tech/https'
@@ -70,7 +66,7 @@ server.listen(443, () => {
70
66
 
71
67
  Hit `https://localhost` and you should see your site with locally-trusted TLS certificates.
72
68
 
73
- @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.
74
70
 
75
71
  ### At hostname with automatically-provisioned Let’s Encrypt certificates.
76
72
 
@@ -92,7 +88,7 @@ server.listen(443, () => {
92
88
 
93
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.
94
90
 
95
- @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.
96
92
 
97
93
  You can find a version of this example in the `/example` folder. To download and run that version:
98
94
 
@@ -134,26 +130,36 @@ Lower-level:
134
130
 
135
131
  ### Auto Encrypt
136
132
 
137
- - Source: https://source.small-tech.org/site.js/lib/auto-encrypt
133
+ - Source: https://github.com/small-tech/auto-encrypt
138
134
  - Package: [@small-tech/auto-encrypt](https://www.npmjs.com/package/@small-tech/auto-encrypt)
139
135
 
140
- 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.)
141
137
 
142
138
  ### Auto Encrypt Localhost
143
139
 
144
- - Source: https://source.small-tech.org/site.js/lib/auto-encrypt-localhost
140
+ - Source: https://codeberg.org/small-tech/auto-encrypt-localhost
145
141
  - Package: [@small-tech/auto-encrypt-localhost](https://www.npmjs.com/package/@small-tech/auto-encrypt-localhost)
146
142
 
147
- 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.).
148
144
 
149
145
  Higher level:
150
146
 
151
147
  ### Site.js
152
148
 
153
149
  - Web site: https://sitejs.org
154
- - Source: https://source.small-tech.org/site.js/app
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.
155
161
 
156
- 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.
157
163
 
158
164
  ## Copyright
159
165
 
@@ -163,4 +169,4 @@ Let’s Encrypt is a trademark of the Internet Security Research Group (ISRG). A
163
169
 
164
170
  ## License
165
171
 
166
- [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": "4.0.0",
3
+ "version": "5.0.1",
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
49
  "@small-tech/auto-encrypt": "^4.0.0",
50
- "@small-tech/auto-encrypt-localhost": "^7.2.0",
51
- "fs-extra": "^9.0.1"
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
- }