@stacksjs/rpx 0.1.1 → 0.2.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/README.md +2 -6
- package/dist/cli.js +57 -8
- package/dist/https.d.ts +3 -0
- package/dist/index.js +57 -7
- package/dist/start.d.ts +1 -1
- package/dist/types.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -46,18 +46,14 @@ import { startProxy } from '@stacksjs/rpx'
|
|
|
46
46
|
export interface ReverseProxyConfig {
|
|
47
47
|
from: string // domain to proxy from, defaults to localhost:3000
|
|
48
48
|
to: string // domain to proxy to, defaults to stacks.localhost
|
|
49
|
-
https: TlsConfig //
|
|
49
|
+
https: boolean | TlsConfig // automatically uses https, defaults to true, also redirects http to https
|
|
50
50
|
verbose: boolean // log verbose output, defaults to false
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
const config: ReverseProxyOptions = {
|
|
54
54
|
from: 'localhost:3000',
|
|
55
55
|
to: 'my-project.localhost',
|
|
56
|
-
https:
|
|
57
|
-
keyPath: './key.pem',
|
|
58
|
-
certPath: './cert.pem',
|
|
59
|
-
caCertPath: './ca.pem',
|
|
60
|
-
},
|
|
56
|
+
https: true,
|
|
61
57
|
}
|
|
62
58
|
|
|
63
59
|
startProxy(config)
|
package/dist/cli.js
CHANGED
|
@@ -17,7 +17,7 @@ var __toESM = (mod, isNodeMode, target) => {
|
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
// bin/cli.ts
|
|
20
|
-
import
|
|
20
|
+
import os9 from "os";
|
|
21
21
|
|
|
22
22
|
// node_modules/@stacksjs/cli/dist/index.js
|
|
23
23
|
import { formatWithOptions } from "util";
|
|
@@ -217845,7 +217845,7 @@ var export_mkdirSync = import_fs_extra.mkdirSync;
|
|
|
217845
217845
|
var export_fsWatch = import_fs_extra.watch;
|
|
217846
217846
|
var export_existsSync = import_fs_extra.pathExists;
|
|
217847
217847
|
// package.json
|
|
217848
|
-
var version = "0.
|
|
217848
|
+
var version = "0.2.0";
|
|
217849
217849
|
|
|
217850
217850
|
// src/config.ts
|
|
217851
217851
|
import os4 from "os";
|
|
@@ -217917,8 +217917,14 @@ import * as fs6 from "fs";
|
|
|
217917
217917
|
import * as http from "http";
|
|
217918
217918
|
import * as https from "https";
|
|
217919
217919
|
import * as net from "net";
|
|
217920
|
+
import os8 from "os";
|
|
217921
|
+
import path9 from "path";
|
|
217920
217922
|
import process23 from "process";
|
|
217921
217923
|
|
|
217924
|
+
// src/https.ts
|
|
217925
|
+
import os7 from "os";
|
|
217926
|
+
import path8 from "path";
|
|
217927
|
+
|
|
217922
217928
|
// node_modules/@stacksjs/tlsx/dist/index.js
|
|
217923
217929
|
import fs22 from "fs";
|
|
217924
217930
|
import os42 from "os";
|
|
@@ -254328,7 +254334,27 @@ var export_pki = import_node_forge2.pki;
|
|
|
254328
254334
|
var export_forge = import_node_forge2.default;
|
|
254329
254335
|
|
|
254330
254336
|
// src/https.ts
|
|
254337
|
+
var defaultHttpsConfig = {
|
|
254338
|
+
domain: "stacks.localhost",
|
|
254339
|
+
hostCertCN: "stacks.localhost",
|
|
254340
|
+
caCertPath: path8.join(os7.homedir(), ".stacks", "ssl", `stacks.localhost.ca.crt`),
|
|
254341
|
+
certPath: path8.join(os7.homedir(), ".stacks", "ssl", `stacks.localhost.crt`),
|
|
254342
|
+
keyPath: path8.join(os7.homedir(), ".stacks", "ssl", `stacks.localhost.crt.key`),
|
|
254343
|
+
altNameIPs: ["127.0.0.1"],
|
|
254344
|
+
altNameURIs: ["localhost"],
|
|
254345
|
+
organizationName: "stacksjs.org",
|
|
254346
|
+
countryName: "US",
|
|
254347
|
+
stateName: "California",
|
|
254348
|
+
localityName: "Playa Vista",
|
|
254349
|
+
commonName: "stacks.localhost",
|
|
254350
|
+
validityDays: 180,
|
|
254351
|
+
verbose: false
|
|
254352
|
+
};
|
|
254331
254353
|
async function generateCertificate(domain) {
|
|
254354
|
+
if (config6.https === true)
|
|
254355
|
+
config6.https = defaultHttpsConfig;
|
|
254356
|
+
else if (config6.https === false)
|
|
254357
|
+
return;
|
|
254332
254358
|
domain = domain ?? config6.https.altNameURIs[0];
|
|
254333
254359
|
log.info(`Generating a self-signed SSL certificate for: ${domain}`);
|
|
254334
254360
|
const caCert = await createRootCA(config6.https);
|
|
@@ -254390,6 +254416,26 @@ process23.on("uncaughtException", (err4) => {
|
|
|
254390
254416
|
});
|
|
254391
254417
|
async function loadSSLConfig(options4) {
|
|
254392
254418
|
debugLog2("ssl", "Loading SSL configuration", options4.verbose);
|
|
254419
|
+
if (options4.https === true) {
|
|
254420
|
+
options4.https = {
|
|
254421
|
+
domain: "stacks.localhost",
|
|
254422
|
+
hostCertCN: "stacks.localhost",
|
|
254423
|
+
caCertPath: path9.join(os8.homedir(), ".stacks", "ssl", `stacks.localhost.ca.crt`),
|
|
254424
|
+
certPath: path9.join(os8.homedir(), ".stacks", "ssl", `stacks.localhost.crt`),
|
|
254425
|
+
keyPath: path9.join(os8.homedir(), ".stacks", "ssl", `stacks.localhost.crt.key`),
|
|
254426
|
+
altNameIPs: ["127.0.0.1"],
|
|
254427
|
+
altNameURIs: ["localhost"],
|
|
254428
|
+
organizationName: "stacksjs.org",
|
|
254429
|
+
countryName: "US",
|
|
254430
|
+
stateName: "California",
|
|
254431
|
+
localityName: "Playa Vista",
|
|
254432
|
+
commonName: "stacks.localhost",
|
|
254433
|
+
validityDays: 180,
|
|
254434
|
+
verbose: false
|
|
254435
|
+
};
|
|
254436
|
+
} else if (options4.https === false) {
|
|
254437
|
+
return null;
|
|
254438
|
+
}
|
|
254393
254439
|
if (!options4.https?.keyPath && !options4.https?.certPath) {
|
|
254394
254440
|
debugLog2("ssl", "No SSL configuration provided", options4.verbose);
|
|
254395
254441
|
return null;
|
|
@@ -254489,10 +254535,14 @@ async function startServer(options4) {
|
|
|
254489
254535
|
if (!options4.to)
|
|
254490
254536
|
options4.to = config6.to;
|
|
254491
254537
|
if (config6.https) {
|
|
254538
|
+
if (config6.https === true)
|
|
254539
|
+
config6.https = defaultHttpsConfig;
|
|
254492
254540
|
const domain = config6.https.altNameURIs?.[0] || new URL(options4.to).hostname;
|
|
254493
|
-
options4.
|
|
254494
|
-
|
|
254495
|
-
|
|
254541
|
+
if (typeof options4.https !== "boolean" && options4.https) {
|
|
254542
|
+
options4.https.keyPath = config6.https.keyPath || path9.join(os8.homedir(), ".stacks", "ssl", `${domain}.crt.key`);
|
|
254543
|
+
options4.https.certPath = config6.https.certPath || path9.join(os8.homedir(), ".stacks", "ssl", `${domain}.crt`);
|
|
254544
|
+
debugLog2("server", `HTTPS enabled, using cert paths: ${options4.https.keyPath}, ${options4.https.certPath}`, options4.verbose);
|
|
254545
|
+
}
|
|
254496
254546
|
}
|
|
254497
254547
|
const fromUrl = new URL(options4.from.startsWith("http") ? options4.from : `http://${options4.from}`);
|
|
254498
254548
|
const toUrl = new URL(options4.to.startsWith("http") ? options4.to : `http://${options4.to}`);
|
|
@@ -254673,8 +254723,7 @@ function startProxy(options4) {
|
|
|
254673
254723
|
debugLog2("proxy", `Starting proxy with options: ${JSON.stringify({
|
|
254674
254724
|
from: finalOptions.from,
|
|
254675
254725
|
to: finalOptions.to,
|
|
254676
|
-
|
|
254677
|
-
certPath: finalOptions.https.certPath
|
|
254726
|
+
https: finalOptions.https
|
|
254678
254727
|
})}`, finalOptions.verbose);
|
|
254679
254728
|
startServer(finalOptions).catch((err4) => {
|
|
254680
254729
|
debugLog2("proxy", `Failed to start proxy: ${err4}`, finalOptions.verbose);
|
|
@@ -254713,7 +254762,7 @@ cli.command("start", "Start the Reverse Proxy Server").option("--from <from>", "
|
|
|
254713
254762
|
});
|
|
254714
254763
|
cli.command("update:etc-hosts", "Update the /etc/hosts file with the proxy domains. Please note, this command requires sudo/admin permissions.").alias("update-etc-hosts").example("sudo reverse-proxy update:etc-hosts").example("sudo reverse-proxy update-etc-hosts").action(async () => {
|
|
254715
254764
|
log.info("Ensuring /etc/hosts file covers the proxy domain/s...");
|
|
254716
|
-
const hostsFilePath =
|
|
254765
|
+
const hostsFilePath = os9.platform() === "win32" ? "C:\\Windows\\System32\\drivers\\etc\\hosts" : "/etc/hosts";
|
|
254717
254766
|
if (config6 && typeof config6 === "object") {
|
|
254718
254767
|
const entriesToAdd = Object.entries(config6).map(([from, to]) => `127.0.0.1 ${to} # reverse-proxy mapping for ${from}`);
|
|
254719
254768
|
entriesToAdd.push("127.0.0.1 localhost # essential localhost mapping");
|
package/dist/https.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -85,6 +85,8 @@ import * as fs3 from "fs";
|
|
|
85
85
|
import * as http from "http";
|
|
86
86
|
import * as https from "https";
|
|
87
87
|
import * as net from "net";
|
|
88
|
+
import os7 from "os";
|
|
89
|
+
import path6 from "path";
|
|
88
90
|
import process3 from "process";
|
|
89
91
|
|
|
90
92
|
// node_modules/@stacksjs/cli/dist/index.js
|
|
@@ -20396,7 +20398,11 @@ var quotes = collect([
|
|
|
20396
20398
|
]);
|
|
20397
20399
|
var export_prompts = import_prompts.default;
|
|
20398
20400
|
// package.json
|
|
20399
|
-
var version = "0.
|
|
20401
|
+
var version = "0.2.0";
|
|
20402
|
+
|
|
20403
|
+
// src/https.ts
|
|
20404
|
+
import os5 from "os";
|
|
20405
|
+
import path4 from "path";
|
|
20400
20406
|
|
|
20401
20407
|
// node_modules/@stacksjs/tlsx/dist/index.js
|
|
20402
20408
|
import fs2 from "fs";
|
|
@@ -56807,7 +56813,27 @@ var export_pki = import_node_forge2.pki;
|
|
|
56807
56813
|
var export_forge = import_node_forge2.default;
|
|
56808
56814
|
|
|
56809
56815
|
// src/https.ts
|
|
56816
|
+
var defaultHttpsConfig = {
|
|
56817
|
+
domain: "stacks.localhost",
|
|
56818
|
+
hostCertCN: "stacks.localhost",
|
|
56819
|
+
caCertPath: path4.join(os5.homedir(), ".stacks", "ssl", `stacks.localhost.ca.crt`),
|
|
56820
|
+
certPath: path4.join(os5.homedir(), ".stacks", "ssl", `stacks.localhost.crt`),
|
|
56821
|
+
keyPath: path4.join(os5.homedir(), ".stacks", "ssl", `stacks.localhost.crt.key`),
|
|
56822
|
+
altNameIPs: ["127.0.0.1"],
|
|
56823
|
+
altNameURIs: ["localhost"],
|
|
56824
|
+
organizationName: "stacksjs.org",
|
|
56825
|
+
countryName: "US",
|
|
56826
|
+
stateName: "California",
|
|
56827
|
+
localityName: "Playa Vista",
|
|
56828
|
+
commonName: "stacks.localhost",
|
|
56829
|
+
validityDays: 180,
|
|
56830
|
+
verbose: false
|
|
56831
|
+
};
|
|
56810
56832
|
async function generateCertificate(domain) {
|
|
56833
|
+
if (config.https === true)
|
|
56834
|
+
config.https = defaultHttpsConfig;
|
|
56835
|
+
else if (config.https === false)
|
|
56836
|
+
return;
|
|
56811
56837
|
domain = domain ?? config.https.altNameURIs[0];
|
|
56812
56838
|
log.info(`Generating a self-signed SSL certificate for: ${domain}`);
|
|
56813
56839
|
const caCert = await createRootCA(config.https);
|
|
@@ -56869,6 +56895,26 @@ process3.on("uncaughtException", (err3) => {
|
|
|
56869
56895
|
});
|
|
56870
56896
|
async function loadSSLConfig(options3) {
|
|
56871
56897
|
debugLog2("ssl", "Loading SSL configuration", options3.verbose);
|
|
56898
|
+
if (options3.https === true) {
|
|
56899
|
+
options3.https = {
|
|
56900
|
+
domain: "stacks.localhost",
|
|
56901
|
+
hostCertCN: "stacks.localhost",
|
|
56902
|
+
caCertPath: path6.join(os7.homedir(), ".stacks", "ssl", `stacks.localhost.ca.crt`),
|
|
56903
|
+
certPath: path6.join(os7.homedir(), ".stacks", "ssl", `stacks.localhost.crt`),
|
|
56904
|
+
keyPath: path6.join(os7.homedir(), ".stacks", "ssl", `stacks.localhost.crt.key`),
|
|
56905
|
+
altNameIPs: ["127.0.0.1"],
|
|
56906
|
+
altNameURIs: ["localhost"],
|
|
56907
|
+
organizationName: "stacksjs.org",
|
|
56908
|
+
countryName: "US",
|
|
56909
|
+
stateName: "California",
|
|
56910
|
+
localityName: "Playa Vista",
|
|
56911
|
+
commonName: "stacks.localhost",
|
|
56912
|
+
validityDays: 180,
|
|
56913
|
+
verbose: false
|
|
56914
|
+
};
|
|
56915
|
+
} else if (options3.https === false) {
|
|
56916
|
+
return null;
|
|
56917
|
+
}
|
|
56872
56918
|
if (!options3.https?.keyPath && !options3.https?.certPath) {
|
|
56873
56919
|
debugLog2("ssl", "No SSL configuration provided", options3.verbose);
|
|
56874
56920
|
return null;
|
|
@@ -56968,10 +57014,14 @@ async function startServer(options3) {
|
|
|
56968
57014
|
if (!options3.to)
|
|
56969
57015
|
options3.to = config.to;
|
|
56970
57016
|
if (config.https) {
|
|
57017
|
+
if (config.https === true)
|
|
57018
|
+
config.https = defaultHttpsConfig;
|
|
56971
57019
|
const domain = config.https.altNameURIs?.[0] || new URL(options3.to).hostname;
|
|
56972
|
-
options3.
|
|
56973
|
-
|
|
56974
|
-
|
|
57020
|
+
if (typeof options3.https !== "boolean" && options3.https) {
|
|
57021
|
+
options3.https.keyPath = config.https.keyPath || path6.join(os7.homedir(), ".stacks", "ssl", `${domain}.crt.key`);
|
|
57022
|
+
options3.https.certPath = config.https.certPath || path6.join(os7.homedir(), ".stacks", "ssl", `${domain}.crt`);
|
|
57023
|
+
debugLog2("server", `HTTPS enabled, using cert paths: ${options3.https.keyPath}, ${options3.https.certPath}`, options3.verbose);
|
|
57024
|
+
}
|
|
56975
57025
|
}
|
|
56976
57026
|
const fromUrl = new URL(options3.from.startsWith("http") ? options3.from : `http://${options3.from}`);
|
|
56977
57027
|
const toUrl = new URL(options3.to.startsWith("http") ? options3.to : `http://${options3.to}`);
|
|
@@ -57152,8 +57202,7 @@ function startProxy(options3) {
|
|
|
57152
57202
|
debugLog2("proxy", `Starting proxy with options: ${JSON.stringify({
|
|
57153
57203
|
from: finalOptions.from,
|
|
57154
57204
|
to: finalOptions.to,
|
|
57155
|
-
|
|
57156
|
-
certPath: finalOptions.https.certPath
|
|
57205
|
+
https: finalOptions.https
|
|
57157
57206
|
})}`, finalOptions.verbose);
|
|
57158
57207
|
startServer(finalOptions).catch((err3) => {
|
|
57159
57208
|
debugLog2("proxy", `Failed to start proxy: ${err3}`, finalOptions.verbose);
|
|
@@ -57184,5 +57233,6 @@ export {
|
|
|
57184
57233
|
startProxies,
|
|
57185
57234
|
startHttpRedirectServer,
|
|
57186
57235
|
setupReverseProxy,
|
|
57187
|
-
config
|
|
57236
|
+
config,
|
|
57237
|
+
cleanup
|
|
57188
57238
|
};
|
package/dist/start.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ProxySetupOptions, ReverseProxyOption, ReverseProxyOptions, SSLConfig } from './types';
|
|
2
2
|
|
|
3
3
|
declare const activeServers: Set<http.Server | https.Server>;
|
|
4
|
-
declare function cleanup(): void;
|
|
4
|
+
export declare function cleanup(): void;
|
|
5
5
|
declare function loadSSLConfig(options: ReverseProxyOption): Promise<SSLConfig | null>;
|
|
6
6
|
declare function isPortInUse(port: number, hostname: string, verbose?: boolean): Promise<boolean>;
|
|
7
7
|
declare function findAvailablePort(startPort: number, hostname: string, verbose?: boolean): Promise<number>;
|
package/dist/types.d.ts
CHANGED