@stacksjs/rpx 0.10.0 → 0.11.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/LICENSE.md +21 -0
- package/README.md +12 -12
- package/dist/bin/cli.js +2 -2
- package/dist/chunk-4csm61sj.js +19 -0
- package/dist/chunk-b6654twv.js +24 -0
- package/dist/chunk-pyeywqa0.js +45 -0
- package/dist/chunk-q7w0fwv3.js +1 -0
- package/dist/chunk-s4etpr6b.js +1 -0
- package/dist/chunk-szmp12hh.js +88 -0
- package/dist/config.d.ts +2 -1
- package/dist/dns.d.ts +21 -0
- package/dist/hosts.d.ts +2 -4
- package/dist/https.d.ts +32 -5
- package/dist/index.d.ts +21 -12
- package/dist/logger.d.ts +10 -0
- package/dist/port-manager.d.ts +25 -0
- package/dist/process-manager.d.ts +8 -143
- package/dist/src/index.js +1 -1
- package/dist/start.d.ts +9 -93
- package/dist/types.d.ts +27 -34
- package/dist/utils.d.ts +29 -7
- package/package.json +21 -26
- package/dist/chunk-1j93wxbr.js +0 -45
- package/dist/chunk-1rkjbws7.js +0 -60
- package/dist/chunk-ny83tnrp.js +0 -24
- package/dist/chunk-zxymjc5f.js +0 -45
- /package/dist/{chunk-7am1svx0.js → chunk-4960052z.js} +0 -0
package/dist/config.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ProxyConfig } from './types';
|
|
2
|
-
|
|
2
|
+
export declare function getConfig(): Promise<ProxyConfig>;
|
|
3
3
|
export declare const defaultConfig: ProxyConfig;
|
|
4
|
+
// For backwards compatibility - synchronous access with default fallback
|
|
4
5
|
export declare const config: ProxyConfig;
|
package/dist/dns.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Start the DNS server
|
|
3
|
+
*/
|
|
4
|
+
export declare function startDnsServer(domains: string[], verbose?: boolean): Promise<boolean>;
|
|
5
|
+
/**
|
|
6
|
+
* Stop the DNS server
|
|
7
|
+
*/
|
|
8
|
+
export declare function stopDnsServer(verbose?: boolean): void;
|
|
9
|
+
/**
|
|
10
|
+
* Check if DNS server is running
|
|
11
|
+
*/
|
|
12
|
+
export declare function isDnsServerRunning(): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Set up the macOS resolver for configured domains
|
|
15
|
+
* Creates /etc/resolver/<tld> files pointing to our local DNS server
|
|
16
|
+
*/
|
|
17
|
+
export declare function setupResolver(verbose?: boolean, domains?: string[]): Promise<boolean>;
|
|
18
|
+
/**
|
|
19
|
+
* Remove the macOS resolver files we created
|
|
20
|
+
*/
|
|
21
|
+
export declare function removeResolver(verbose?: boolean): Promise<void>;
|
package/dist/hosts.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
declare const execAsync: unknown;
|
|
2
|
-
export declare const hostsFilePath: string;
|
|
3
|
-
declare function execSudo(command: string): Promise<void>;
|
|
4
1
|
export declare function addHosts(hosts: string[], verbose?: boolean): Promise<void>;
|
|
5
2
|
export declare function removeHosts(hosts: string[], verbose?: boolean): Promise<void>;
|
|
6
|
-
export declare function checkHosts(hosts: string[], verbose?: boolean): Promise<boolean[]>;
|
|
3
|
+
export declare function checkHosts(hosts: string[], verbose?: boolean): Promise<boolean[]>;
|
|
4
|
+
export declare const hostsFilePath: string;
|
package/dist/https.d.ts
CHANGED
|
@@ -1,12 +1,39 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { config } from './config';
|
|
2
|
+
import type { ProxyConfigs, ProxyOption, ProxyOptions, SSLConfig, TlsConfig } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Resolves SSL paths based on configuration
|
|
5
|
+
*/
|
|
3
6
|
export declare function resolveSSLPaths(options: ProxyConfigs, defaultConfig: typeof config): TlsConfig;
|
|
7
|
+
// Generate wildcard patterns for a domain
|
|
4
8
|
export declare function generateWildcardPatterns(domain: string): string[];
|
|
5
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Generates SSL file paths based on domain
|
|
11
|
+
*/
|
|
12
|
+
export declare function generateSSLPaths(options?: ProxyOptions): {
|
|
13
|
+
caCertPath: string
|
|
14
|
+
certPath: string
|
|
15
|
+
keyPath: string
|
|
16
|
+
};
|
|
6
17
|
export declare function getAllDomains(options: ProxyOption | ProxyOptions): Set<string>;
|
|
18
|
+
/**
|
|
19
|
+
* Load SSL certificates from files or use provided strings
|
|
20
|
+
*/
|
|
7
21
|
export declare function loadSSLConfig(options: ProxyOption): Promise<SSLConfig | null>;
|
|
22
|
+
/**
|
|
23
|
+
* Force trust a certificate - exposing for direct use
|
|
24
|
+
*/
|
|
25
|
+
export declare function forceTrustCertificate(certPath: string): Promise<boolean>;
|
|
8
26
|
export declare function generateCertificate(options: ProxyOptions): Promise<void>;
|
|
9
|
-
export declare function getSSLConfig():
|
|
27
|
+
export declare function getSSLConfig(): { key: string, cert: string, ca?: string } | null;
|
|
28
|
+
// needs to accept the options
|
|
10
29
|
export declare function checkExistingCertificates(options?: ProxyOptions): Promise<SSLConfig | null>;
|
|
11
30
|
export declare function httpsConfig(options: ProxyOption | ProxyOptions, verbose?: boolean): TlsConfig;
|
|
12
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Clean up SSL certificates for a specific domain
|
|
33
|
+
*/
|
|
34
|
+
export declare function cleanupCertificates(domain: string, verbose?: boolean): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Checks if a certificate is trusted by the system (macOS only for now)
|
|
37
|
+
* If options.regenerateUntrustedCerts is false, always returns true (skips trust check)
|
|
38
|
+
*/
|
|
39
|
+
export declare function isCertTrusted(certPath: string, options?: { verbose?: boolean, regenerateUntrustedCerts?: boolean }): Promise<boolean>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
export { config, config as defaultConfig } from './config';
|
|
2
|
+
export {
|
|
3
|
+
addHosts,
|
|
4
|
+
checkHosts,
|
|
5
|
+
removeHosts,
|
|
6
|
+
} from './hosts';
|
|
7
|
+
export {
|
|
8
|
+
checkExistingCertificates,
|
|
9
|
+
cleanupCertificates,
|
|
10
|
+
forceTrustCertificate,
|
|
11
|
+
generateCertificate,
|
|
12
|
+
httpsConfig,
|
|
13
|
+
isCertTrusted,
|
|
14
|
+
loadSSLConfig,
|
|
15
|
+
} from './https';
|
|
16
|
+
export { DefaultPortManager, findAvailablePort, isPortInUse, portManager } from './port-manager';
|
|
17
|
+
export { cleanup } from './start';
|
|
18
|
+
export { startProxies, startProxy, startServer } from './start';
|
|
19
|
+
export * from './types';
|
|
20
|
+
export * from './utils';
|
|
21
|
+
export default startProxiesFunc;
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const log: {
|
|
2
|
+
info: (...args: any[]) => void
|
|
3
|
+
success: (...args: any[]) => void
|
|
4
|
+
warn: (...args: any[]) => void
|
|
5
|
+
error: (...args: any[]) => void
|
|
6
|
+
debug: (...args: any[]) => void
|
|
7
|
+
log: (...args: any[]) => void
|
|
8
|
+
start: (...args: any[]) => void
|
|
9
|
+
box: (...args: any[]) => void
|
|
10
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { PortManager } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Check if a port is in use
|
|
4
|
+
*/
|
|
5
|
+
export declare function isPortInUse(port: number, hostname: string, verbose?: boolean): Promise<boolean>;
|
|
6
|
+
/**
|
|
7
|
+
* Find next available port
|
|
8
|
+
*/
|
|
9
|
+
export declare function findAvailablePort(startPort: number, hostname: string, verbose?: boolean, maxAttempts?: any): Promise<number>;
|
|
10
|
+
/**
|
|
11
|
+
* Test if a port is actually connectable
|
|
12
|
+
*/
|
|
13
|
+
export declare function testPortConnectivity(port: number, hostname: string, timeout?: any, verbose?: boolean): Promise<boolean>;
|
|
14
|
+
// Global port manager instance
|
|
15
|
+
export declare const portManager: DefaultPortManager;
|
|
16
|
+
export declare class DefaultPortManager implements PortManager {
|
|
17
|
+
usedPorts: Set<number>;
|
|
18
|
+
private hostname: string;
|
|
19
|
+
private verbose?: boolean;
|
|
20
|
+
private maxRetries: number;
|
|
21
|
+
constructor(hostname?: string, verbose?: boolean, maxRetries?: any);
|
|
22
|
+
getNextAvailablePort(startPort: number, testConnectivity?: any): Promise<number>;
|
|
23
|
+
private findNextAvailablePort(startPort: number, testConnectivity?: any): Promise<number>;
|
|
24
|
+
releasePort(port: number): void;
|
|
25
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ChildProcess } from 'node:child_process';
|
|
2
2
|
import type { StartOptions } from './types';
|
|
3
|
-
|
|
3
|
+
export declare const processManager: ProcessManager;
|
|
4
4
|
export declare interface ManagedProcess {
|
|
5
5
|
command: string
|
|
6
6
|
cwd: string
|
|
@@ -8,145 +8,10 @@ export declare interface ManagedProcess {
|
|
|
8
8
|
env?: Record<string, string>
|
|
9
9
|
}
|
|
10
10
|
export declare class ProcessManager {
|
|
11
|
-
private processes: Map<string, ManagedProcess
|
|
12
|
-
private isShuttingDown
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const [cmd, ...args] = options.command.split(' ')
|
|
21
|
-
const cwd = options.cwd || process.cwd()
|
|
22
|
-
|
|
23
|
-
debugLog('start', `Starting process ${id}:`, verbose)
|
|
24
|
-
debugLog('start', ` Command: ${cmd} ${args.join(' ')}`, verbose)
|
|
25
|
-
debugLog('start', ` Working directory: ${cwd}`, verbose)
|
|
26
|
-
debugLog('start', ` Environment variables: ${JSON.stringify(options.env)}`, verbose)
|
|
27
|
-
|
|
28
|
-
const childProcess = spawn(cmd, args, {
|
|
29
|
-
cwd,
|
|
30
|
-
env: { ...process.env, ...options.env },
|
|
31
|
-
shell: true,
|
|
32
|
-
stdio: 'inherit',
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
this.processes.set(id, {
|
|
36
|
-
command: options.command,
|
|
37
|
-
cwd,
|
|
38
|
-
process: childProcess,
|
|
39
|
-
env: options.env,
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
return new Promise((resolve, reject) => {
|
|
43
|
-
childProcess.on('error', (err) => {
|
|
44
|
-
if (!this.isShuttingDown) {
|
|
45
|
-
debugLog('start', `Process ${id} failed to start: ${err}`, verbose)
|
|
46
|
-
this.processes.delete(id)
|
|
47
|
-
reject(err)
|
|
48
|
-
process.emit('SIGINT')
|
|
49
|
-
}
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
childProcess.on('exit', (code) => {
|
|
53
|
-
if (!this.isShuttingDown && code !== null && code !== 0) {
|
|
54
|
-
debugLog('start', `Process ${id} exited with code ${code}`, verbose)
|
|
55
|
-
this.processes.delete(id)
|
|
56
|
-
reject(new Error(`Process ${id} exited with code ${code}`))
|
|
57
|
-
process.emit('SIGINT')
|
|
58
|
-
}
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
if (verbose) {
|
|
62
|
-
childProcess.stdout?.on('data', (data) => {
|
|
63
|
-
debugLog('process', `[${id}] ${data.toString().trim()}`, true)
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
childProcess.stderr?.on('data', (data) => {
|
|
67
|
-
debugLog('process', `[${id}] ERR: ${data.toString().trim()}`, true)
|
|
68
|
-
})
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
setTimeout(() => {
|
|
72
|
-
if (!this.isShuttingDown && childProcess.killed) {
|
|
73
|
-
this.processes.delete(id)
|
|
74
|
-
reject(new Error(`Process ${id} was killed during startup`))
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
debugLog('start', `Process ${id} started successfully`, verbose)
|
|
78
|
-
resolve()
|
|
79
|
-
}
|
|
80
|
-
}, 1000)
|
|
81
|
-
})
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
async stopProcess(id: string, verbose?: boolean): Promise<void> {
|
|
85
|
-
const managed = this.processes.get(id)
|
|
86
|
-
if (!managed?.process) {
|
|
87
|
-
debugLog('start', `No process found for ${id}`, verbose)
|
|
88
|
-
return
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
debugLog('start', `Stopping process ${id}`, verbose)
|
|
92
|
-
|
|
93
|
-
return new Promise((resolve) => {
|
|
94
|
-
if (!managed.process) {
|
|
95
|
-
resolve()
|
|
96
|
-
return
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
managed.process.once('exit', () => {
|
|
100
|
-
this.processes.delete(id)
|
|
101
|
-
debugLog('start', `Process ${id} stopped`, verbose)
|
|
102
|
-
resolve()
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
try {
|
|
106
|
-
managed.process.kill('SIGTERM')
|
|
107
|
-
|
|
108
|
-
setTimeout(() => {
|
|
109
|
-
if (managed.process) {
|
|
110
|
-
debugLog('start', `Force killing process ${id}`, verbose)
|
|
111
|
-
try {
|
|
112
|
-
managed.process.kill('SIGKILL')
|
|
113
|
-
}
|
|
114
|
-
catch (err) {
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}, 3000)
|
|
118
|
-
}
|
|
119
|
-
catch (err) {
|
|
120
|
-
debugLog('start', `Error stopping process ${id}: ${err}`, verbose)
|
|
121
|
-
this.processes.delete(id)
|
|
122
|
-
resolve()
|
|
123
|
-
}
|
|
124
|
-
})
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
async stopAll(verbose?: boolean): Promise<void> {
|
|
128
|
-
if (this.isShuttingDown) {
|
|
129
|
-
debugLog('start', 'Already shutting down, skipping duplicate stopAll call', verbose)
|
|
130
|
-
return
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
this.isShuttingDown = true
|
|
134
|
-
debugLog('start', 'Stopping all processes', verbose)
|
|
135
|
-
|
|
136
|
-
const promises = Array.from(this.processes.keys()).map(id =>
|
|
137
|
-
this.stopProcess(id, verbose).catch((err) => {
|
|
138
|
-
log.error(`Failed to stop process ${id}:`, err)
|
|
139
|
-
}),
|
|
140
|
-
)
|
|
141
|
-
|
|
142
|
-
await Promise.allSettled(promises)
|
|
143
|
-
this.processes.clear()
|
|
144
|
-
this.isShuttingDown = false
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
isRunning(id: string): boolean {
|
|
148
|
-
const managed = this.processes.get(id)
|
|
149
|
-
return !!managed?.process && !managed.process.killed
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
export declare const processManager: ProcessManager;
|
|
11
|
+
private processes: Map<string, ManagedProcess>;
|
|
12
|
+
private isShuttingDown: any;
|
|
13
|
+
startProcess(id: string, options: StartOptions, verbose?: boolean): Promise<void>;
|
|
14
|
+
stopProcess(id: string, verbose?: boolean): Promise<void>;
|
|
15
|
+
stopAll(verbose?: boolean): Promise<void>;
|
|
16
|
+
isRunning(id: string): boolean;
|
|
17
|
+
}
|
package/dist/src/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{b as o,c as t,d as e,e as f,f as a,g as i,h as s,i as p,j as c,k as x,l as n,m,n as g,o as C,p as P,r as l,s as d,t as u,u as r}from"../chunk-szmp12hh.js";import"../chunk-b6654twv.js";import{C as L,D as U,E as j,F as q,G as z,H as B,I as G,J as I,K as J,L as K,M as N}from"../chunk-4csm61sj.js";import"../chunk-4960052z.js";var F=r;export{d as startServer,u as startProxy,r as startProxies,N as safeDeleteFile,e as removeHosts,P as portManager,a as loadSSLConfig,z as isValidRootCA,J as isSingleProxyOptions,K as isSingleProxyConfig,m as isPortInUse,I as isMultiProxyOptions,G as isMultiProxyConfig,n as isCertTrusted,c as httpsConfig,L as getSudoPassword,B as getPrimaryDomain,s as generateCertificate,i as forceTrustCertificate,g as findAvailablePort,q as extractHostname,U as execSudoSync,o as defaultConfig,F as default,j as debugLog,o as config,x as cleanupCertificates,l as cleanup,f as checkHosts,p as checkExistingCertificates,t as addHosts,C as DefaultPortManager};
|
package/dist/start.d.ts
CHANGED
|
@@ -1,94 +1,10 @@
|
|
|
1
|
-
import type { CleanupOptions, ProxyOption } from './types';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
declare
|
|
5
|
-
declare type AnyServerType = http.Server | https.Server | http2.Http2SecureServer
|
|
6
|
-
type AnyIncomingMessage = http.IncomingMessage | http2.Http2ServerRequest
|
|
7
|
-
type AnyServerResponse = http.ServerResponse | http2.Http2ServerResponse
|
|
8
|
-
|
|
9
|
-
let isCleaningUp = false
|
|
10
|
-
|
|
11
|
-
export async function cleanup(options?: CleanupOptions): Promise<void> {
|
|
12
|
-
if (isCleaningUp) {
|
|
13
|
-
debugLog('cleanup', 'Cleanup already in progress, skipping', options?.verbose)
|
|
14
|
-
return
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
isCleaningUp = true
|
|
18
|
-
debugLog('cleanup', 'Starting cleanup process', options?.verbose)
|
|
19
|
-
|
|
20
|
-
try {
|
|
21
|
-
await processManager.stopAll(options?.verbose)
|
|
22
|
-
|
|
23
|
-
log.info('Shutting down proxy servers...')
|
|
24
|
-
|
|
25
|
-
const cleanupPromises: Promise<void>[] = []
|
|
26
|
-
|
|
27
|
-
const serverClosePromises = Array.from(activeServers).map(server =>
|
|
28
|
-
new Promise<void>((resolve) => {
|
|
29
|
-
server.close(() => {
|
|
30
|
-
debugLog('cleanup', 'Server closed successfully', options?.verbose)
|
|
31
|
-
resolve()
|
|
32
|
-
})
|
|
33
|
-
}),
|
|
34
|
-
)
|
|
35
|
-
cleanupPromises.push(...serverClosePromises)
|
|
36
|
-
|
|
37
|
-
if (options?.hosts && options.domains?.length) {
|
|
38
|
-
debugLog('cleanup', 'Cleaning up hosts file entries', options?.verbose)
|
|
39
|
-
const domainsToClean = options.domains.filter(domain => !domain.includes('localhost'))
|
|
40
|
-
|
|
41
|
-
if (domainsToClean.length > 0) {
|
|
42
|
-
log.info('Cleaning up hosts file entries...')
|
|
43
|
-
cleanupPromises.push(
|
|
44
|
-
removeHosts(domainsToClean, options?.verbose)
|
|
45
|
-
.then(() => {
|
|
46
|
-
debugLog('cleanup', `Removed hosts entries for ${domainsToClean.join(', ')}`, options?.verbose)
|
|
47
|
-
})
|
|
48
|
-
.catch((err) => {
|
|
49
|
-
debugLog('cleanup', `Failed to remove hosts entries: ${err}`, options?.verbose)
|
|
50
|
-
log.warn(`Failed to clean up hosts file entries for ${domainsToClean.join(', ')}:`, err)
|
|
51
|
-
}),
|
|
52
|
-
)
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (options?.certs && options.domains?.length) {
|
|
57
|
-
debugLog('cleanup', 'Cleaning up SSL certificates', options?.verbose)
|
|
58
|
-
log.info('Cleaning up SSL certificates...')
|
|
59
|
-
|
|
60
|
-
const certCleanupPromises = options.domains.map(async (domain) => {
|
|
61
|
-
try {
|
|
62
|
-
await cleanupCertificates(domain, options?.verbose)
|
|
63
|
-
debugLog('cleanup', `Removed certificates for ${domain}`, options?.verbose)
|
|
64
|
-
}
|
|
65
|
-
catch (err) {
|
|
66
|
-
debugLog('cleanup', `Failed to remove certificates for ${domain}: ${err}`, options?.verbose)
|
|
67
|
-
log.warn(`Failed to clean up certificates for ${domain}:`, err)
|
|
68
|
-
}
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
cleanupPromises.push(...certCleanupPromises)
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
await Promise.allSettled(cleanupPromises)
|
|
75
|
-
debugLog('cleanup', 'All cleanup tasks completed successfully', options?.verbose)
|
|
76
|
-
log.success('All cleanup tasks completed successfully')
|
|
77
|
-
}
|
|
78
|
-
catch (err) {
|
|
79
|
-
debugLog('cleanup', `Error during cleanup: ${err}`, options?.verbose)
|
|
80
|
-
log.error('Error during cleanup:', err)
|
|
81
|
-
}
|
|
82
|
-
finally {
|
|
83
|
-
isCleaningUp = false
|
|
84
|
-
process.exit(0)
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
let isHandlingSignal = false
|
|
89
|
-
declare function signalHandler(): void;
|
|
90
|
-
declare function isPortInUse(port: number, hostname: string, verbose?: boolean): Promise<boolean>;
|
|
91
|
-
declare function normalizeHeaders(headers: IncomingHttpHeaders): http.OutgoingHttpHeaders;
|
|
92
|
-
declare function setupServer(serverInstance: AnyServerType): void;
|
|
1
|
+
import type { CleanupOptions, ProxyOption, ProxyOptions, ProxySetupOptions, SingleProxyConfig } from './types';
|
|
2
|
+
export declare function cleanup(options?: CleanupOptions): Promise<void>;
|
|
3
|
+
export declare function startServer(options: SingleProxyConfig): Promise<void>;
|
|
4
|
+
export declare function setupProxy(options: ProxySetupOptions): Promise<void>;
|
|
93
5
|
export declare function startHttpRedirectServer(verbose?: boolean): void;
|
|
94
|
-
export declare function startProxy(options: ProxyOption): void;
|
|
6
|
+
export declare function startProxy(options: ProxyOption): void;
|
|
7
|
+
export declare function startProxies(options?: ProxyOptions): Promise<void>;
|
|
8
|
+
declare type AnyServerType = http.Server | https.Server | http2.Http2SecureServer
|
|
9
|
+
declare type AnyIncomingMessage = http.IncomingMessage | http2.Http2ServerRequest
|
|
10
|
+
declare type AnyServerResponse = http.ServerResponse | http2.Http2ServerResponse
|
package/dist/types.d.ts
CHANGED
|
@@ -1,28 +1,23 @@
|
|
|
1
1
|
import type { TlsConfig, TlsOption } from '@stacksjs/tlsx';
|
|
2
|
-
|
|
3
|
-
export type { TlsConfig, TlsOption }
|
|
2
|
+
export type { TlsConfig, TlsOption };
|
|
4
3
|
export declare interface StartOptions {
|
|
5
4
|
command: string
|
|
6
5
|
cwd?: string
|
|
7
6
|
env?: Record<string, string>
|
|
8
7
|
}
|
|
9
8
|
export declare interface BaseProxyConfig {
|
|
10
|
-
from: string
|
|
11
|
-
to: string
|
|
9
|
+
from: string
|
|
10
|
+
to: string
|
|
12
11
|
start?: StartOptions
|
|
13
12
|
}
|
|
14
|
-
export declare
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
verbose: boolean
|
|
13
|
+
export declare interface CleanupConfig {
|
|
14
|
+
domains: string[]
|
|
15
|
+
hosts: boolean
|
|
16
|
+
certs: boolean
|
|
17
|
+
verbose: boolean
|
|
18
|
+
vitePluginUsage?: boolean
|
|
21
19
|
}
|
|
22
|
-
|
|
23
|
-
export type CleanupOptions = Partial<CleanupConfig>
|
|
24
|
-
|
|
25
|
-
export interface SharedProxyConfig {
|
|
20
|
+
export declare interface SharedProxyConfig {
|
|
26
21
|
https: boolean | TlsOption
|
|
27
22
|
cleanup: boolean | CleanupOptions
|
|
28
23
|
vitePluginUsage: boolean
|
|
@@ -30,30 +25,21 @@ export interface SharedProxyConfig {
|
|
|
30
25
|
_cachedSSLConfig?: SSLConfig | null
|
|
31
26
|
start?: StartOptions
|
|
32
27
|
cleanUrls: boolean
|
|
28
|
+
changeOrigin?: boolean
|
|
29
|
+
regenerateUntrustedCerts?: boolean
|
|
33
30
|
}
|
|
31
|
+
export declare interface SingleProxyConfig extends BaseProxyConfig, SharedProxyConfig {
|
|
34
32
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
export interface SingleProxyConfig extends BaseProxyConfig, SharedProxyConfig {}
|
|
38
|
-
|
|
39
|
-
export interface MultiProxyConfig extends SharedProxyConfig {
|
|
33
|
+
}
|
|
34
|
+
export declare interface MultiProxyConfig extends SharedProxyConfig {
|
|
40
35
|
proxies: Array<BaseProxyConfig & { cleanUrls: boolean }>
|
|
41
36
|
}
|
|
42
|
-
|
|
43
|
-
export type ProxyConfig = SingleProxyConfig
|
|
44
|
-
export type ProxyConfigs = SingleProxyConfig | MultiProxyConfig
|
|
45
|
-
|
|
46
|
-
export type BaseProxyOption = Partial<BaseProxyConfig>
|
|
47
|
-
export type ProxyOption = Partial<SingleProxyConfig>
|
|
48
|
-
export type ProxyOptions = Partial<SingleProxyConfig> | Partial<MultiProxyConfig>
|
|
49
|
-
|
|
50
|
-
export interface SSLConfig {
|
|
37
|
+
export declare interface SSLConfig {
|
|
51
38
|
key: string
|
|
52
39
|
cert: string
|
|
53
40
|
ca?: string | string[]
|
|
54
41
|
}
|
|
55
|
-
|
|
56
|
-
export interface ProxySetupOptions extends Omit<ProxyOption, 'from'> {
|
|
42
|
+
export declare interface ProxySetupOptions extends Omit<ProxyOption, 'from'> {
|
|
57
43
|
fromPort: number
|
|
58
44
|
sourceUrl: Pick<URL, 'hostname' | 'host'>
|
|
59
45
|
ssl: SSLConfig | null
|
|
@@ -61,8 +47,15 @@ export interface ProxySetupOptions extends Omit<ProxyOption, 'from'> {
|
|
|
61
47
|
to: string
|
|
62
48
|
portManager?: PortManager
|
|
63
49
|
}
|
|
64
|
-
|
|
65
|
-
export interface PortManager {
|
|
50
|
+
export declare interface PortManager {
|
|
66
51
|
usedPorts: Set<number>
|
|
67
52
|
getNextAvailablePort: (startPort: number) => Promise<number>
|
|
68
|
-
}
|
|
53
|
+
}
|
|
54
|
+
export type BaseProxyOptions = Partial<BaseProxyConfig>
|
|
55
|
+
export type CleanupOptions = Partial<CleanupConfig>
|
|
56
|
+
export type SharedProxyOptions = Partial<SharedProxyConfig>
|
|
57
|
+
export type ProxyConfig = SingleProxyConfig
|
|
58
|
+
export type ProxyConfigs = SingleProxyConfig | MultiProxyConfig
|
|
59
|
+
export type BaseProxyOption = Partial<BaseProxyConfig>
|
|
60
|
+
export type ProxyOption = Partial<SingleProxyConfig>
|
|
61
|
+
export type ProxyOptions = Partial<SingleProxyConfig> | Partial<MultiProxyConfig>
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,15 +1,37 @@
|
|
|
1
|
-
import type { ProxyConfigs, ProxyOption } from './types';
|
|
2
|
-
|
|
1
|
+
import type { MultiProxyConfig, ProxyConfigs, ProxyOption, ProxyOptions, SingleProxyConfig } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Get sudo password from environment variable if set
|
|
4
|
+
*/
|
|
5
|
+
export declare function getSudoPassword(): string | undefined;
|
|
6
|
+
/**
|
|
7
|
+
* Execute a command with sudo, using SUDO_PASSWORD if available
|
|
8
|
+
*/
|
|
9
|
+
export declare function execSudoSync(command: string): string;
|
|
3
10
|
export declare function debugLog(category: string, message: string, verbose?: boolean): void;
|
|
11
|
+
/**
|
|
12
|
+
* Extracts hostnames from proxy configuration
|
|
13
|
+
*/
|
|
4
14
|
export declare function extractHostname(options: ProxyOption | ProxyOptions): string[];
|
|
5
|
-
declare interface RootCA {
|
|
6
|
-
certificate: string
|
|
7
|
-
privateKey: string
|
|
8
|
-
}
|
|
9
15
|
export declare function isValidRootCA(value: unknown): value is RootCA;
|
|
10
16
|
export declare function getPrimaryDomain(options?: ProxyOption | ProxyOptions): string;
|
|
17
|
+
/**
|
|
18
|
+
* Type guard for multi-proxy configuration
|
|
19
|
+
*/
|
|
11
20
|
export declare function isMultiProxyConfig(options: ProxyConfigs | ProxyOptions): options is MultiProxyConfig;
|
|
21
|
+
/**
|
|
22
|
+
* Type guard to check if options are for multi-proxy configuration
|
|
23
|
+
*/
|
|
12
24
|
export declare function isMultiProxyOptions(options: ProxyOption | ProxyOptions): options is MultiProxyConfig;
|
|
25
|
+
/**
|
|
26
|
+
* Type guard to check if options are for single-proxy configuration
|
|
27
|
+
*/
|
|
13
28
|
export declare function isSingleProxyOptions(options: ProxyOption | ProxyOptions): options is SingleProxyConfig;
|
|
14
29
|
export declare function isSingleProxyConfig(options: ProxyConfigs | ProxyOptions): options is SingleProxyConfig;
|
|
15
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Safely delete a file if it exists
|
|
32
|
+
*/
|
|
33
|
+
export declare function safeDeleteFile(filePath: string, verbose?: boolean): Promise<void>;
|
|
34
|
+
declare interface RootCA {
|
|
35
|
+
certificate: string
|
|
36
|
+
privateKey: string
|
|
37
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/rpx",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.11.0",
|
|
5
5
|
"description": "A modern and smart reverse proxy.",
|
|
6
6
|
"author": "Chris Breuer <chris@stacksjs.org>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
],
|
|
27
27
|
"exports": {
|
|
28
28
|
".": {
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
29
30
|
"import": "./dist/src/index.js"
|
|
30
31
|
}
|
|
31
32
|
},
|
|
@@ -35,7 +36,10 @@
|
|
|
35
36
|
"rpx": "./dist/bin/cli.js",
|
|
36
37
|
"reverse-proxy": "./dist/bin/cli.js"
|
|
37
38
|
},
|
|
38
|
-
"files": [
|
|
39
|
+
"files": [
|
|
40
|
+
"README.md",
|
|
41
|
+
"dist"
|
|
42
|
+
],
|
|
39
43
|
"scripts": {
|
|
40
44
|
"build": "bun build.ts && bun run compile",
|
|
41
45
|
"compile": "bun build ./bin/cli.ts --compile --minify --outfile bin/rpx",
|
|
@@ -49,41 +53,32 @@
|
|
|
49
53
|
"lint:fix": "bunx --bun eslint . --fix",
|
|
50
54
|
"fresh": "bunx rimraf node_modules/ bun.lock && bun i",
|
|
51
55
|
"changelog": "changelogen --output CHANGELOG.md",
|
|
52
|
-
"prepublishOnly": "bun --bun run build && bun run compile:all",
|
|
53
|
-
"release": "bun run changelog && bumpp package.json --all",
|
|
56
|
+
"prepublishOnly": "bun --bun run build && bun run compile:all && bun run zip",
|
|
54
57
|
"test": "bun test",
|
|
55
58
|
"typecheck": "bunx tsc --noEmit",
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
+
"zip": "bun run zip:all",
|
|
60
|
+
"zip:all": "bun run zip:linux-x64 && bun run zip:linux-arm64 && bun run zip:windows-x64 && bun run zip:darwin-x64 && bun run zip:darwin-arm64",
|
|
61
|
+
"zip:linux-x64": "zip -j bin/rpx-linux-x64.zip bin/rpx-linux-x64",
|
|
62
|
+
"zip:linux-arm64": "zip -j bin/rpx-linux-arm64.zip bin/rpx-linux-arm64",
|
|
63
|
+
"zip:windows-x64": "zip -j bin/rpx-windows-x64.zip bin/rpx-windows-x64.exe",
|
|
64
|
+
"zip:darwin-x64": "zip -j bin/rpx-darwin-x64.zip bin/rpx-darwin-x64",
|
|
65
|
+
"zip:darwin-arm64": "zip -j bin/rpx-darwin-arm64.zip bin/rpx-darwin-arm64"
|
|
59
66
|
},
|
|
60
67
|
"devDependencies": {
|
|
61
|
-
"@iconify-json/carbon": "^1.2.5",
|
|
62
|
-
"@shikijs/vitepress-twoslash": "^2.1.0",
|
|
63
|
-
"@stacksjs/eslint-config": "^3.15.1-beta.4",
|
|
64
68
|
"@stacksjs/tlsx": "^0.10.0",
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"bumpp": "^10.0.1",
|
|
68
|
-
"bun-plugin-dtsx": "^0.21.9",
|
|
69
|
-
"bunfig": "^0.5.3",
|
|
69
|
+
"bun-plugin-dtsx": "^0.21.17",
|
|
70
|
+
"bunfig": "^0.15.6",
|
|
70
71
|
"cac": "^6.7.14",
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"typescript": "^5.7.3",
|
|
74
|
-
"unocss": "^65.4.3",
|
|
75
|
-
"unplugin-icons": "^22.0.0",
|
|
76
|
-
"unplugin-vue-components": "^28.0.0",
|
|
77
|
-
"vite-plugin-pwa": "^0.21.1",
|
|
78
|
-
"vitepress": "^1.6.3"
|
|
79
|
-
},
|
|
80
|
-
"overrides": {
|
|
81
|
-
"unconfig": "0.3.10"
|
|
72
|
+
"consola": "^3.4.2",
|
|
73
|
+
"typescript": "^5.9.3"
|
|
82
74
|
},
|
|
83
75
|
"simple-git-hooks": {
|
|
84
76
|
"pre-commit": "bunx lint-staged"
|
|
85
77
|
},
|
|
86
78
|
"lint-staged": {
|
|
87
79
|
"*.{js,ts}": "bunx eslint . --fix"
|
|
80
|
+
},
|
|
81
|
+
"dependencies": {
|
|
82
|
+
"picocolors": "^1.1.1"
|
|
88
83
|
}
|
|
89
84
|
}
|