@stacksjs/rpx 0.5.0 → 0.5.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/dist/cli.js +62 -103
- package/dist/hosts.d.ts +2 -1
- package/dist/https.d.ts +0 -4
- package/dist/index.js +309 -349
- package/dist/utils.d.ts +6 -2
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -20461,7 +20461,7 @@ var quotes = collect([
|
|
|
20461
20461
|
]);
|
|
20462
20462
|
var export_prompts = import_prompts.default;
|
|
20463
20463
|
// package.json
|
|
20464
|
-
var version = "0.5.
|
|
20464
|
+
var version = "0.5.1";
|
|
20465
20465
|
|
|
20466
20466
|
// src/config.ts
|
|
20467
20467
|
import { homedir } from "os";
|
|
@@ -57099,9 +57099,15 @@ function extractHostname(options3) {
|
|
|
57099
57099
|
function isValidRootCA(value) {
|
|
57100
57100
|
return typeof value === "object" && value !== null && "certificate" in value && "privateKey" in value && typeof value.certificate === "string" && typeof value.privateKey === "string";
|
|
57101
57101
|
}
|
|
57102
|
-
|
|
57103
|
-
|
|
57104
|
-
|
|
57102
|
+
function getPrimaryDomain(options3) {
|
|
57103
|
+
if (!options3)
|
|
57104
|
+
return "stacks.localhost";
|
|
57105
|
+
if (isMultiProxyOptions(options3) && options3.proxies.length > 0)
|
|
57106
|
+
return options3.proxies[0].to || "stacks.localhost";
|
|
57107
|
+
if (isSingleProxyOptions(options3))
|
|
57108
|
+
return options3.to || "stacks.localhost";
|
|
57109
|
+
return "stacks.localhost";
|
|
57110
|
+
}
|
|
57105
57111
|
function isMultiProxyConfig(options3) {
|
|
57106
57112
|
return "proxies" in options3 && Array.isArray(options3.proxies);
|
|
57107
57113
|
}
|
|
@@ -57111,6 +57117,9 @@ function isMultiProxyOptions(options3) {
|
|
|
57111
57117
|
function isSingleProxyOptions(options3) {
|
|
57112
57118
|
return "to" in options3 && typeof options3.to === "string";
|
|
57113
57119
|
}
|
|
57120
|
+
|
|
57121
|
+
// src/https.ts
|
|
57122
|
+
var cachedSSLConfig = null;
|
|
57114
57123
|
function resolveSSLPaths(options3, defaultConfig3) {
|
|
57115
57124
|
const domain = isMultiProxyConfig(options3) ? options3.proxies[0].to || "stacks.localhost" : options3.to || "stacks.localhost";
|
|
57116
57125
|
if (typeof options3.https === "object" && typeof defaultConfig3.https === "object") {
|
|
@@ -57154,15 +57163,6 @@ function generateWildcardPatterns(domain) {
|
|
|
57154
57163
|
patterns.add(`*.${parts.slice(1).join(".")}`);
|
|
57155
57164
|
return Array.from(patterns);
|
|
57156
57165
|
}
|
|
57157
|
-
function getPrimaryDomain(options3) {
|
|
57158
|
-
if (!options3)
|
|
57159
|
-
return "stacks.localhost";
|
|
57160
|
-
if (isMultiProxyOptions(options3) && options3.proxies.length > 0)
|
|
57161
|
-
return options3.proxies[0].to || "stacks.localhost";
|
|
57162
|
-
if (isSingleProxyOptions(options3))
|
|
57163
|
-
return options3.to || "stacks.localhost";
|
|
57164
|
-
return "stacks.localhost";
|
|
57165
|
-
}
|
|
57166
57166
|
function generateSSLPaths(options3) {
|
|
57167
57167
|
const domain = getPrimaryDomain(options3);
|
|
57168
57168
|
let basePath = "";
|
|
@@ -57244,7 +57244,6 @@ async function generateCertificate2(options3) {
|
|
|
57244
57244
|
log.info("Generating Root CA certificate...");
|
|
57245
57245
|
const caCert = await createRootCA(rootCAConfig);
|
|
57246
57246
|
const hostConfig = httpsConfig(options3, options3.verbose);
|
|
57247
|
-
console.log("hostConfig", hostConfig);
|
|
57248
57247
|
log.info(`Generating host certificate for: ${domains.join(", ")}`);
|
|
57249
57248
|
const hostCert = await generateCertificate({
|
|
57250
57249
|
...hostConfig,
|
|
@@ -57348,49 +57347,22 @@ import * as net from "net";
|
|
|
57348
57347
|
import process9 from "process";
|
|
57349
57348
|
|
|
57350
57349
|
// src/hosts.ts
|
|
57351
|
-
import {
|
|
57350
|
+
import { exec as exec2 } from "child_process";
|
|
57352
57351
|
import fs5 from "fs";
|
|
57353
57352
|
import os3 from "os";
|
|
57354
57353
|
import path4 from "path";
|
|
57355
57354
|
import process3 from "process";
|
|
57355
|
+
import { promisify } from "util";
|
|
57356
|
+
var execAsync = promisify(exec2);
|
|
57356
57357
|
var hostsFilePath = process3.platform === "win32" ? path4.join(process3.env.windir || "C:\\Windows", "System32", "drivers", "etc", "hosts") : "/etc/hosts";
|
|
57357
|
-
async function
|
|
57358
|
-
|
|
57359
|
-
|
|
57360
|
-
|
|
57361
|
-
|
|
57362
|
-
|
|
57363
|
-
|
|
57364
|
-
|
|
57365
|
-
if (operation === "append") {
|
|
57366
|
-
const currentContent = fs5.readFileSync(hostsFilePath, "utf8");
|
|
57367
|
-
fs5.writeFileSync(tmpFile, currentContent + content, "utf8");
|
|
57368
|
-
} else {
|
|
57369
|
-
fs5.writeFileSync(tmpFile, content, "utf8");
|
|
57370
|
-
}
|
|
57371
|
-
const sudo = spawn("sudo", ["cp", tmpFile, hostsFilePath]);
|
|
57372
|
-
sudo.on("close", (code) => {
|
|
57373
|
-
try {
|
|
57374
|
-
fs5.unlinkSync(tmpFile);
|
|
57375
|
-
if (code === 0)
|
|
57376
|
-
resolve4();
|
|
57377
|
-
else
|
|
57378
|
-
reject(new Error(`sudo process exited with code ${code}`));
|
|
57379
|
-
} catch (err3) {
|
|
57380
|
-
reject(err3);
|
|
57381
|
-
}
|
|
57382
|
-
});
|
|
57383
|
-
sudo.on("error", (err3) => {
|
|
57384
|
-
try {
|
|
57385
|
-
fs5.unlinkSync(tmpFile);
|
|
57386
|
-
} catch {
|
|
57387
|
-
}
|
|
57388
|
-
reject(err3);
|
|
57389
|
-
});
|
|
57390
|
-
} catch (err3) {
|
|
57391
|
-
reject(err3);
|
|
57392
|
-
}
|
|
57393
|
-
});
|
|
57358
|
+
async function execSudo(command) {
|
|
57359
|
+
if (process3.platform === "win32")
|
|
57360
|
+
throw new Error("Administrator privileges required on Windows");
|
|
57361
|
+
try {
|
|
57362
|
+
await execAsync(`sudo ${command}`);
|
|
57363
|
+
} catch (error) {
|
|
57364
|
+
throw new Error(`Failed to execute sudo command: ${error.message}`);
|
|
57365
|
+
}
|
|
57394
57366
|
}
|
|
57395
57367
|
async function addHosts(hosts, verbose) {
|
|
57396
57368
|
debugLog2("hosts", `Adding hosts: ${hosts.join(", ")}`, verbose);
|
|
@@ -57412,35 +57384,29 @@ async function addHosts(hosts, verbose) {
|
|
|
57412
57384
|
127.0.0.1 ${host}
|
|
57413
57385
|
::1 ${host}`).join(`
|
|
57414
57386
|
`);
|
|
57387
|
+
const tmpFile = path4.join(os3.tmpdir(), "hosts.tmp");
|
|
57388
|
+
await fs5.promises.writeFile(tmpFile, existingContent + hostEntries, "utf8");
|
|
57415
57389
|
try {
|
|
57416
|
-
await
|
|
57390
|
+
await execSudo(`cp "${tmpFile}" "${hostsFilePath}"`);
|
|
57417
57391
|
log.success(`Added new hosts: ${newEntries.join(", ")}`);
|
|
57418
|
-
} catch (
|
|
57419
|
-
|
|
57420
|
-
|
|
57421
|
-
|
|
57422
|
-
await sudoWrite("append", hostEntries);
|
|
57423
|
-
log.success(`Added new hosts with sudo: ${newEntries.join(", ")}`);
|
|
57424
|
-
} catch (sudoErr) {
|
|
57425
|
-
log.error("Failed to modify hosts file automatically");
|
|
57426
|
-
log.warn("Please add these entries to your hosts file manually:");
|
|
57427
|
-
hostEntries.split(`
|
|
57392
|
+
} catch (error) {
|
|
57393
|
+
log.error("Failed to modify hosts file automatically");
|
|
57394
|
+
log.warn("Please add these entries to your hosts file manually:");
|
|
57395
|
+
hostEntries.split(`
|
|
57428
57396
|
`).forEach((entry) => log.warn(entry));
|
|
57429
|
-
|
|
57430
|
-
|
|
57397
|
+
if (process3.platform === "win32") {
|
|
57398
|
+
log.warn(`
|
|
57431
57399
|
On Windows:`);
|
|
57432
|
-
|
|
57433
|
-
|
|
57434
|
-
} else {
|
|
57435
|
-
log.warn(`
|
|
57436
|
-
On Unix systems:`);
|
|
57437
|
-
log.warn(`sudo nano ${hostsFilePath}`);
|
|
57438
|
-
}
|
|
57439
|
-
throw new Error("Failed to modify hosts file: manual intervention required");
|
|
57440
|
-
}
|
|
57400
|
+
log.warn("1. Run notepad as administrator");
|
|
57401
|
+
log.warn("2. Open C:\\Windows\\System32\\drivers\\etc\\hosts");
|
|
57441
57402
|
} else {
|
|
57442
|
-
|
|
57403
|
+
log.warn(`
|
|
57404
|
+
On Unix systems:`);
|
|
57405
|
+
log.warn(`sudo nano ${hostsFilePath}`);
|
|
57443
57406
|
}
|
|
57407
|
+
throw new Error("Failed to modify hosts file: manual intervention required");
|
|
57408
|
+
} finally {
|
|
57409
|
+
fs5.unlinkSync(tmpFile);
|
|
57444
57410
|
}
|
|
57445
57411
|
} catch (err3) {
|
|
57446
57412
|
const error = err3;
|
|
@@ -57466,38 +57432,32 @@ async function removeHosts(hosts, verbose) {
|
|
|
57466
57432
|
const newContent = `${filteredLines.join(`
|
|
57467
57433
|
`)}
|
|
57468
57434
|
`;
|
|
57435
|
+
const tmpFile = path4.join(os3.tmpdir(), "hosts.tmp");
|
|
57436
|
+
await fs5.promises.writeFile(tmpFile, newContent, "utf8");
|
|
57469
57437
|
try {
|
|
57470
|
-
await
|
|
57438
|
+
await execSudo(`cp "${tmpFile}" "${hostsFilePath}"`);
|
|
57471
57439
|
log.success("Hosts removed successfully");
|
|
57472
|
-
} catch (
|
|
57473
|
-
|
|
57474
|
-
|
|
57475
|
-
|
|
57476
|
-
|
|
57477
|
-
|
|
57478
|
-
|
|
57479
|
-
|
|
57480
|
-
|
|
57481
|
-
|
|
57482
|
-
log.warn("# Added by rpx");
|
|
57483
|
-
log.warn(`127.0.0.1 ${host}`);
|
|
57484
|
-
log.warn(`::1 ${host}`);
|
|
57485
|
-
});
|
|
57486
|
-
if (process3.platform === "win32") {
|
|
57487
|
-
log.warn(`
|
|
57440
|
+
} catch (error) {
|
|
57441
|
+
log.error("Failed to modify hosts file automatically");
|
|
57442
|
+
log.warn("Please remove these entries from your hosts file manually:");
|
|
57443
|
+
hosts.forEach((host) => {
|
|
57444
|
+
log.warn("# Added by rpx");
|
|
57445
|
+
log.warn(`127.0.0.1 ${host}`);
|
|
57446
|
+
log.warn(`::1 ${host}`);
|
|
57447
|
+
});
|
|
57448
|
+
if (process3.platform === "win32") {
|
|
57449
|
+
log.warn(`
|
|
57488
57450
|
On Windows:`);
|
|
57489
|
-
|
|
57490
|
-
|
|
57491
|
-
} else {
|
|
57492
|
-
log.warn(`
|
|
57493
|
-
On Unix systems:`);
|
|
57494
|
-
log.warn(`sudo nano ${hostsFilePath}`);
|
|
57495
|
-
}
|
|
57496
|
-
throw new Error("Failed to modify hosts file: manual intervention required");
|
|
57497
|
-
}
|
|
57451
|
+
log.warn("1. Run notepad as administrator");
|
|
57452
|
+
log.warn("2. Open C:\\Windows\\System32\\drivers\\etc\\hosts");
|
|
57498
57453
|
} else {
|
|
57499
|
-
|
|
57454
|
+
log.warn(`
|
|
57455
|
+
On Unix systems:`);
|
|
57456
|
+
log.warn(`sudo nano ${hostsFilePath}`);
|
|
57500
57457
|
}
|
|
57458
|
+
throw new Error("Failed to modify hosts file: manual intervention required");
|
|
57459
|
+
} finally {
|
|
57460
|
+
fs5.unlinkSync(tmpFile);
|
|
57501
57461
|
}
|
|
57502
57462
|
} catch (err3) {
|
|
57503
57463
|
const error = err3;
|
|
@@ -57953,7 +57913,6 @@ async function startProxies(options3) {
|
|
|
57953
57913
|
var cli = new CAC("reverse-proxy");
|
|
57954
57914
|
cli.command("start", "Start the Reverse Proxy Server").option("--from <from>", "The URL to proxy from").option("--to <to>", "The URL to proxy to").option("--key-path <path>", "Absolute path to the SSL key").option("--cert-path <path>", "Absolute path to the SSL certificate").option("--ca-cert-path <path>", "Absolute path to the SSL CA certificate").option("--etc-hosts-cleanup", "Cleanup /etc/hosts on exit").option("--verbose", "Enable verbose logging").example("reverse-proxy start --from localhost:5173 --to my-project.localhost").example("reverse-proxy start --from localhost:3000 --to my-project.localhost/api").example("reverse-proxy start --from localhost:3000 --to localhost:3001").example("reverse-proxy start --from localhost:5173 --to my-project.test --key-path /absolute/path/to/key --cert-path /absolute/path/to/cert").action(async (options3) => {
|
|
57955
57915
|
if (!options3?.from || !options3.to) {
|
|
57956
|
-
console.log("in here", config4);
|
|
57957
57916
|
return startProxies(config4);
|
|
57958
57917
|
}
|
|
57959
57918
|
return startProxy({
|
package/dist/hosts.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
declare const execAsync: unknown;
|
|
1
2
|
export declare const hostsFilePath: string;
|
|
2
|
-
declare function
|
|
3
|
+
declare function execSudo(command: string): Promise<void>;
|
|
3
4
|
export declare function addHosts(hosts: string[], verbose?: boolean): Promise<void>;
|
|
4
5
|
export declare function removeHosts(hosts: string[], verbose?: boolean): Promise<void>;
|
|
5
6
|
export declare function checkHosts(hosts: string[], verbose?: boolean): Promise<boolean[]>;
|
package/dist/https.d.ts
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import type { ReverseProxyConfigs, ReverseProxyOption, ReverseProxyOptions, TlsConfig } from './types';
|
|
2
2
|
|
|
3
|
-
export declare function isMultiProxyConfig(options: ReverseProxyConfigs): options is MultiReverseProxyConfig;
|
|
4
|
-
export declare function isMultiProxyOptions(options: ReverseProxyOption | ReverseProxyOptions): options is MultiReverseProxyConfig;
|
|
5
|
-
export declare function isSingleProxyOptions(options: ReverseProxyOption | ReverseProxyOptions): options is SingleReverseProxyConfig;
|
|
6
3
|
export declare function resolveSSLPaths(options: ReverseProxyConfigs, defaultConfig: typeof config): TlsConfig;
|
|
7
4
|
export declare function generateWildcardPatterns(domain: string): string[];
|
|
8
|
-
export declare function getPrimaryDomain(options?: ReverseProxyOption | ReverseProxyOptions): string;
|
|
9
5
|
export declare function generateSSLPaths(options?: ReverseProxyOptions): void;
|
|
10
6
|
export declare function getAllDomains(options: ReverseProxyOption | ReverseProxyOptions): Set<string>;
|
|
11
7
|
export declare function loadSSLConfig(options: ReverseProxyOption): Promise<SSLConfig | null>;
|