@jsenv/https-local 3.2.30 → 3.2.32

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,22 +1,63 @@
1
- # https local
1
+ # HTTPS Local [![npm package](https://img.shields.io/npm/v/@jsenv/https-local.svg?logo=npm&label=package)](https://www.npmjs.com/package/@jsenv/https-local)
2
+
3
+ A programmatic way to generate locally trusted certificates for HTTPS development.
4
+
5
+ 🔒 Generate certificates trusted by your operating system and browsers
6
+ 🌐 Perfect for local HTTPS development
7
+ 🖥️ Works on macOS, Linux, and Windows
8
+ ⚡ Simple API for certificate management
9
+
10
+ ## Table of Contents
11
+
12
+ - [HTTPS Local ](#https-local-)
13
+ - [Table of Contents](#table-of-contents)
14
+ - [Quick Start](#quick-start)
15
+ - [How to Use](#how-to-use)
16
+ - [1. Install the Root Certificate](#1-install-the-root-certificate)
17
+ - [2. Request Certificate for Your Server](#2-request-certificate-for-your-server)
18
+ - [3. Start the Server](#3-start-the-server)
19
+ - [Certificate Expiration](#certificate-expiration)
20
+ - [JavaScript API](#javascript-api)
21
+ - [requestCertificate](#requestcertificate)
22
+ - [verifyHostsFile](#verifyhostsfile)
23
+ - [Auto Update Hosts](#auto-update-hosts)
24
+ - [installCertificateAuthority](#installcertificateauthority)
25
+ - [Auto Trust](#auto-trust)
26
+
27
+ ## Quick Start
2
28
 
3
- [![npm package](https://img.shields.io/npm/v/@jsenv/https-local.svg?logo=npm&label=package)](https://www.npmjs.com/package/@jsenv/https-local)
29
+ ```console
30
+ # Install the package
31
+ npm install @jsenv/https-local
4
32
 
5
- A programmatic way to generate locally trusted certificates.
33
+ # Install and trust the root certificate
34
+ npx @jsenv/https-local install --trust
35
+ ```
6
36
 
7
- Generate certificate(s) trusted by your operating system and browsers.
8
- This certificate can be used to start your development server in HTTPS.
9
- Works on mac, linux and windows.
37
+ ```js
38
+ // In your server file
39
+ import { createServer } from "node:https";
40
+ import { requestCertificate } from "@jsenv/https-local";
10
41
 
11
- # How to use
42
+ const { certificate, privateKey } = requestCertificate();
43
+ const server = createServer(
44
+ {
45
+ cert: certificate,
46
+ key: privateKey,
47
+ },
48
+ (request, response) => {
49
+ response.end("Hello HTTPS world!");
50
+ },
51
+ ).listen(8443, () => {
52
+ console.log("HTTPS server running at https://localhost:8443");
53
+ });
54
+ ```
12
55
 
13
- The following steps can be taken to start a local server in https.
56
+ ## How to Use
14
57
 
15
- 1. Install the root certificate using https-local
16
- 2. Request certificate for your server
17
- 3. Start that server
58
+ The following steps can be taken to start a local server in HTTPS:
18
59
 
19
- ## 1. Install the root certificate
60
+ ### 1. Install the Root Certificate
20
61
 
21
62
  ```console
22
63
  npx @jsenv/https-local install --trust
@@ -24,10 +65,10 @@ npx @jsenv/https-local install --trust
24
65
 
25
66
  This will install a root certificate valid for 20 years.
26
67
 
27
- - Re-executing this command will log the current root certificate validity and trust status.
68
+ - Re-executing this command will log the current root certificate validity and trust status
28
69
  - Re-executing this command 20 years later would reinstall a root certificate and re-trust it
29
70
 
30
- ## 2. Request certificate for your server
71
+ ### 2. Request Certificate for Your Server
31
72
 
32
73
  _start_dev_server.mjs_
33
74
 
@@ -55,33 +96,32 @@ server.listen(8080);
55
96
  console.log(`Server listening at https://local.example:8080`);
56
97
  ```
57
98
 
58
- ## 3. Start the server
99
+ ### 3. Start the Server
59
100
 
60
101
  ```console
61
102
  node ./start_dev_server.mjs
62
103
  ```
63
104
 
64
- At this stage you have a server running in https.
65
- The rest of this documentation goes into more details.
105
+ At this stage you have a server running in HTTPS.
66
106
 
67
- # Certificate expiration
107
+ ## Certificate Expiration
68
108
 
69
109
  | Certificate | Expires after | How to renew? |
70
110
  | ----------- | ------------- | ------------------------------------ |
71
111
  | server | 1 year | Re-run _requestCertificate_ |
72
- | authority | 20 year | Re-run _installCertificateAuthority_ |
112
+ | authority | 20 years | Re-run _installCertificateAuthority_ |
73
113
 
74
- The **server certificate** expires after one year which is the maximum duration allowed by web browsers.
114
+ The **server certificate** expires after one year, which is the maximum duration allowed by web browsers.
75
115
  In the unlikely scenario where a local server is running for more than a year without interruption, restart it to re-run requestCertificate.
76
116
 
77
- The **authority root certificate** expires after 20 years which is close to the maximum allowed duration.
78
- In the very unlikely scenario where you are using the same machine for more than 20 years, re-execute [installCertificateAuthority](#installCertificateAuthority) to update certificate authority then restart your server.
117
+ The **authority root certificate** expires after 20 years, which is close to the maximum allowed duration.
118
+ In the very unlikely scenario where you are using the same machine for more than 20 years, re-execute [installCertificateAuthority](#installcertificateauthority) to update certificate authority then restart your server.
79
119
 
80
- # JavaScript API
120
+ ## JavaScript API
81
121
 
82
- ## requestCertificate
122
+ ### requestCertificate
83
123
 
84
- _requestCertificate_ function returns a certificate and private key that can be used to start a server in HTTPS.
124
+ The `requestCertificate` function returns a certificate and private key that can be used to start a server in HTTPS.
85
125
 
86
126
  ```js
87
127
  import { createServer } from "node:https";
@@ -92,12 +132,11 @@ const { certificate, privateKey } = requestCertificate({
92
132
  });
93
133
  ```
94
134
 
95
- [installCertificateAuthority](#installCertificateAuthority) must be called before this function.
135
+ [installCertificateAuthority](#installcertificateauthority) must be called before this function.
96
136
 
97
- ## verifyHostsFile
137
+ ### verifyHostsFile
98
138
 
99
- This function is not mandatory to obtain the https certificates.
100
- But it is useful to programmatically verify ip mappings that are important for your local server are present in hosts file.
139
+ This function is not mandatory to obtain the HTTPS certificates, but it is useful to programmatically verify IP mappings that are important for your local server are present in hosts file.
101
140
 
102
141
  ```js
103
142
  import { verifyHostsFile } from "@jsenv/https-local";
@@ -109,10 +148,10 @@ await verifyHostsFile({
109
148
  });
110
149
  ```
111
150
 
112
- Find below logs written in terminal when this function is executed.
151
+ Find below logs written in terminal when this function is executed:
113
152
 
114
153
  <details>
115
- <summary>mac and linux</summary>
154
+ <summary>Mac and Linux output</summary>
116
155
 
117
156
  ```console
118
157
  > node ./verify_hosts.mjs
@@ -128,7 +167,7 @@ Check hosts file content...
128
167
  </details>
129
168
 
130
169
  <details>
131
- <summary>windows</summary>
170
+ <summary>Windows output</summary>
132
171
 
133
172
  ```console
134
173
  > node ./verify_hosts.mjs
@@ -143,9 +182,9 @@ C:\\Windows\\System32\\Drivers\\etc\\hosts
143
182
 
144
183
  </details>
145
184
 
146
- ### Auto update hosts
185
+ #### Auto Update Hosts
147
186
 
148
- It's possible to update hosts file programmatically using _tryToUpdateHostsFile_.
187
+ It's possible to update hosts file programmatically using `tryToUpdateHostsFile`:
149
188
 
150
189
  ```js
151
190
  import { verifyHostsFile } from "@jsenv/https-local";
@@ -159,7 +198,7 @@ await verifyHostsFile({
159
198
  ```
160
199
 
161
200
  <details>
162
- <summary>mac and linux</summary>
201
+ <summary>Mac and Linux output</summary>
163
202
 
164
203
  ```console
165
204
  Check hosts file content...
@@ -182,7 +221,7 @@ Check hosts file content...
182
221
  </details>
183
222
 
184
223
  <details>
185
- <summary>windows</summary>
224
+ <summary>Windows output</summary>
186
225
 
187
226
  ```console
188
227
  Check hosts file content...
@@ -204,9 +243,9 @@ Check hosts file content...
204
243
 
205
244
  </details>
206
245
 
207
- ## installCertificateAuthority
246
+ ### installCertificateAuthority
208
247
 
209
- _installCertificateAuthority_ function generates a certificate authority valid for 20 years.
248
+ The `installCertificateAuthority` function generates a certificate authority valid for 20 years.
210
249
  This certificate authority is needed to generate local certificates that will be trusted by the operating system and web browsers.
211
250
 
212
251
  ```js
@@ -215,12 +254,10 @@ import { installCertificateAuthority } from "@jsenv/https-local";
215
254
  await installCertificateAuthority();
216
255
  ```
217
256
 
218
- By default, trusting authority root certificate is a manual process. This manual process is documented in [BenMorel/dev-certificates#Import the CA in your browser](https://github.com/BenMorel/dev-certificates/tree/c10cd68945da772f31815b7a36721ddf848ff3a3#import-the-ca-in-your-browser). This process can be done programmatically as explained in [Auto trust](#Auto-trust).
219
-
220
- Find below logs written in terminal when this function is executed.
257
+ By default, trusting authority root certificate is a manual process. This manual process is documented in [BenMorel/dev-certificates#Import the CA in your browser](https://github.com/BenMorel/dev-certificates/tree/c10cd68945da772f31815b7a36721ddf848ff3a3#import-the-ca-in-your-browser). This process can be done programmatically as explained in [Auto Trust](#auto-trust).
221
258
 
222
259
  <details>
223
- <summary>mac</summary>
260
+ <summary>macOS output</summary>
224
261
 
225
262
  ```console
226
263
  > node ./install_certificate_authority.mjs
@@ -232,7 +269,7 @@ Generating authority root certificate with a validity of 20 years...
232
269
  ℹ You should add root certificate to firefox
233
270
  ```
234
271
 
235
- _second execution logs_
272
+ _Second execution logs_
236
273
 
237
274
  ```console
238
275
  > node ./install_certificate_authority.mjs
@@ -251,7 +288,7 @@ Check if certificate is in firefox...
251
288
  </details>
252
289
 
253
290
  <details>
254
- <summary>linux</summary>
291
+ <summary>Linux output</summary>
255
292
 
256
293
  ```console
257
294
  > node ./install_certificate_authority.mjs
@@ -264,7 +301,7 @@ Generating authority root certificate with a validity of 20 years...
264
301
  ℹ You should add certificate to firefox
265
302
  ```
266
303
 
267
- _second execution logs_
304
+ _Second execution logs_
268
305
 
269
306
  ```console
270
307
  > node ./install_certificate_authority.mjs
@@ -285,7 +322,7 @@ Check if certificate is in firefox...
285
322
  </details>
286
323
 
287
324
  <details>
288
- <summary>windows</summary>
325
+ <summary>Windows output</summary>
289
326
 
290
327
  ```console
291
328
  > node ./install_certificate_authority.mjs
@@ -297,7 +334,7 @@ Generating authority root certificate with a validity of 20 years...
297
334
  ℹ You should add certificate to firefox
298
335
  ```
299
336
 
300
- _second execution logs_
337
+ _Second execution logs_
301
338
 
302
339
  ```console
303
340
  > node ./install_certificate_authority.mjs
@@ -315,9 +352,9 @@ Check if certificate is trusted by firefox...
315
352
 
316
353
  </details>
317
354
 
318
- ### Auto trust
355
+ #### Auto Trust
319
356
 
320
- It's possible to trust root certificate programmatically using _tryToTrust_
357
+ It's possible to trust root certificate programmatically using `tryToTrust`:
321
358
 
322
359
  ```js
323
360
  import { installCertificateAuthority } from "@jsenv/https-local";
@@ -328,7 +365,7 @@ await installCertificateAuthority({
328
365
  ```
329
366
 
330
367
  <details>
331
- <summary>mac</summary>
368
+ <summary>macOS output</summary>
332
369
 
333
370
  ```console
334
371
  > node ./install_certificate_authority.mjs
@@ -344,7 +381,7 @@ Adding certificate to firefox...
344
381
  ✔ certificate added to Firefox
345
382
  ```
346
383
 
347
- _second execution logs_
384
+ _Second execution logs_
348
385
 
349
386
  ```console
350
387
  > node ./install_certificate_authority.mjs
@@ -363,7 +400,7 @@ Check if certificate is in Firefox...
363
400
  </details>
364
401
 
365
402
  <details>
366
- <summary>linux</summary>
403
+ <summary>Linux output</summary>
367
404
 
368
405
  ```console
369
406
  > node ./install_certificate_authority.mjs
@@ -390,7 +427,7 @@ Adding certificate to firefox...
390
427
  ✔ certificate added to firefox
391
428
  ```
392
429
 
393
- _second execution logs_
430
+ _Second execution logs_
394
431
 
395
432
  ```console
396
433
  > node ./install_certificate_authority.mjs
@@ -411,7 +448,7 @@ Check if certificate is in firefox...
411
448
  </details>
412
449
 
413
450
  <details>
414
- <summary>windows</summary>
451
+ <summary>Windows output</summary>
415
452
 
416
453
  ```console
417
454
  > node ./install_certificate_authority.mjs
@@ -430,7 +467,7 @@ Check if certificate is trusted by firefox...
430
467
  ℹ unable to detect if certificate is trusted by firefox (not implemented on windows)
431
468
  ```
432
469
 
433
- _second execution logs_
470
+ _Second execution logs_
434
471
 
435
472
  ```console
436
473
  > node ./install_certificate_authority.mjs
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@jsenv/https-local",
3
- "version": "3.2.30",
3
+ "version": "3.2.32",
4
4
  "description": "A programmatic way to generate locally trusted certificates",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "https://github.com/jsenv/core",
9
- "directory": "packages/independent/tooling/https-local"
9
+ "directory": "packages/tooling/https-local"
10
10
  },
11
11
  "publishConfig": {
12
12
  "access": "public"
@@ -40,12 +40,18 @@
40
40
  "hosts:ensure-localhost-mappings": "node ./scripts/hosts/ensure_localhost_mappings.mjs"
41
41
  },
42
42
  "dependencies": {
43
- "@jsenv/filesystem": "4.15.1",
44
- "@jsenv/humanize": "1.5.1",
45
- "@jsenv/urls": "2.7.3",
43
+ "@jsenv/filesystem": "4.15.3",
44
+ "@jsenv/humanize": "1.6.0",
45
+ "@jsenv/urls": "2.8.0",
46
46
  "command-exists": "1.2.9",
47
47
  "node-forge": "1.3.1",
48
48
  "sudo-prompt": "9.2.1",
49
49
  "which": "5.0.0"
50
+ },
51
+ "devDependencies": {
52
+ "@jsenv/assert": "../assert",
53
+ "@jsenv/https-local": "./",
54
+ "@jsenv/performance-impact": "../performance-impact",
55
+ "playwright": "1.51.1"
50
56
  }
51
57
  }
@@ -38,7 +38,7 @@ npx @jsenv/https-local uninstall
38
38
  npx @jsenv/https-local localhost-mapping
39
39
  Ensure localhost mapping to 127.0.0.1 is set on the filesystem
40
40
 
41
- https://github.com/jsenv/core/tree/main/packages/independent/https-local
41
+ https://github.com/jsenv/core/tree/main/packages/tooling/https-local
42
42
 
43
43
  `);
44
44