@small-tech/https 6.0.0 → 6.1.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/index.d.ts +62 -0
- package/index.js +15 -2
- package/package.json +5 -3
package/index.d.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ClientRequest,
|
|
3
|
+
IncomingMessage,
|
|
4
|
+
ServerResponse,
|
|
5
|
+
RequestListener,
|
|
6
|
+
} from "node:http"
|
|
7
|
+
import { RequestOptions, Server, ServerOptions } from "node:https"
|
|
8
|
+
import EventEmitter from "node:events"
|
|
9
|
+
import { AutoEncryptedLocalhostServer } from "@small-tech/auto-encrypt-localhost"
|
|
10
|
+
import { AutoEncryptedServer, AutoEncryptOptions, IPAddresses } from "@small-tech/auto-encrypt"
|
|
11
|
+
|
|
12
|
+
export { IPAddresses }
|
|
13
|
+
|
|
14
|
+
export class Events extends EventEmitter {
|
|
15
|
+
CREATING_SERVER: symbol
|
|
16
|
+
SERVER_CREATED: symbol
|
|
17
|
+
SERVER_CLOSED: symbol
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const events: Events
|
|
21
|
+
export const SMALL_TECH_HOME_PATH: string
|
|
22
|
+
export const DEFAULT_SETTINGS_PATH: string
|
|
23
|
+
|
|
24
|
+
export type SmallTechHttpsOptions = AutoEncryptOptions & {
|
|
25
|
+
staging?: boolean
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function request(
|
|
29
|
+
options: RequestOptions | string | URL,
|
|
30
|
+
callback?: (res: IncomingMessage) => void
|
|
31
|
+
): ClientRequest
|
|
32
|
+
|
|
33
|
+
export function request(
|
|
34
|
+
url: string | URL,
|
|
35
|
+
options: RequestOptions,
|
|
36
|
+
callback?: (res: IncomingMessage) => void
|
|
37
|
+
): ClientRequest
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
declare const _default: typeof import("node:https") & {
|
|
41
|
+
createServer: typeof createServer
|
|
42
|
+
request: typeof request
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
declare class https {
|
|
46
|
+
static async createServer<
|
|
47
|
+
Request extends typeof IncomingMessage = typeof IncomingMessage,
|
|
48
|
+
Response extends typeof ServerResponse = typeof ServerResponse
|
|
49
|
+
>(
|
|
50
|
+
requestListener?: RequestListener<Request, Response>
|
|
51
|
+
): Promise<AutoEncryptedLocalhostServer> | Promise<AutoEncryptedServer>
|
|
52
|
+
|
|
53
|
+
static async createServer<
|
|
54
|
+
Request extends typeof IncomingMessage = typeof IncomingMessage,
|
|
55
|
+
Response extends typeof ServerResponse = typeof ServerResponse
|
|
56
|
+
>(
|
|
57
|
+
options: SmallTechHttpsOptions,
|
|
58
|
+
requestListener?: RequestListener<Request, Response>
|
|
59
|
+
): Promise<AutoEncryptedLocalhostServer> | Promise<AutoEncryptedServer>
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export default https
|
package/index.js
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@small-tech/https
|
|
3
|
+
|
|
4
|
+
Provides isomorphic access to Auto Encryt and Auto Encrypt Localhost, creating the correct server (localhost using local certificate authority or globally-reachable using Let’s Encrypt TLS certificates).
|
|
5
|
+
|
|
6
|
+
Copyright ⓒ 2019-present Aral Balkan, Small Technology Foundation
|
|
7
|
+
*/
|
|
1
8
|
import os from 'node:os'
|
|
2
9
|
import process from 'node:process'
|
|
3
10
|
import path from 'node:path'
|
|
4
11
|
import EventEmitter from 'node:events'
|
|
5
12
|
|
|
6
13
|
import AutoEncrypt from '@small-tech/auto-encrypt'
|
|
14
|
+
export { IPAddresses } from '@small-tech/auto-encrypt'
|
|
7
15
|
import AutoEncryptLocalhost from '@small-tech/auto-encrypt-localhost'
|
|
8
16
|
|
|
9
17
|
class Events extends EventEmitter {
|
|
@@ -38,7 +46,7 @@ export default class https {
|
|
|
38
46
|
static async createServer (options = {}, listener) {
|
|
39
47
|
// There can be only server per node process. Enforce that here.
|
|
40
48
|
if (this.server !== null) {
|
|
41
|
-
console.warn('Create server called when server already exists for this process. Returning existing server instance.')
|
|
49
|
+
console.warn('Create server called when server already exists for this process. This is likely a coding error. Returning existing server instance.')
|
|
42
50
|
return this.server
|
|
43
51
|
}
|
|
44
52
|
|
|
@@ -49,8 +57,13 @@ export default class https {
|
|
|
49
57
|
}
|
|
50
58
|
|
|
51
59
|
const localDomains = ['localhost', 'place1.localhost', 'place2.localhost', 'place3.localhost', 'place4.localhost']
|
|
52
|
-
const
|
|
60
|
+
const domainsListDoestExistOrIncludesALocalDomain = options.domains == undefined || options.domains.some(domain => localDomains.includes(domain))
|
|
61
|
+
const automaticIPAddressDetectionRequested = options.ipv4 || options.ipv6
|
|
62
|
+
|
|
63
|
+
const isLocal = domainsListDoestExistOrIncludesALocalDomain && !automaticIPAddressDetectionRequested
|
|
64
|
+
|
|
53
65
|
const serverScope = isLocal ? 'local' : 'global'
|
|
66
|
+
|
|
54
67
|
const settingsPath = options.settingsPath ? path.join(path.resolve(options.settingsPath), serverScope) : path.join(DEFAULT_SETTINGS_PATH, serverScope)
|
|
55
68
|
options.settingsPath = settingsPath
|
|
56
69
|
|
package/package.json
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@small-tech/https",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.1.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": [
|
|
7
|
-
"lib"
|
|
7
|
+
"lib",
|
|
8
|
+
"index.d.ts"
|
|
8
9
|
],
|
|
9
10
|
"type": "module",
|
|
11
|
+
"types": "index.d.ts",
|
|
10
12
|
"engines": {
|
|
11
13
|
"node": ">=18.20.0"
|
|
12
14
|
},
|
|
@@ -49,7 +51,7 @@
|
|
|
49
51
|
},
|
|
50
52
|
"license": "AGPL-3.0",
|
|
51
53
|
"dependencies": {
|
|
52
|
-
"@small-tech/auto-encrypt": "^5.
|
|
54
|
+
"@small-tech/auto-encrypt": "^5.1.0",
|
|
53
55
|
"@small-tech/auto-encrypt-localhost": "^10.0.0"
|
|
54
56
|
},
|
|
55
57
|
"devDependencies": {
|