@stacksjs/rpx 0.4.1 → 0.5.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/dist/cli.js +353 -226
- package/dist/config.d.ts +3 -2
- package/dist/https.d.ts +13 -7
- package/dist/index.js +461 -324
- package/dist/start.d.ts +2 -4
- package/dist/types.d.ts +12 -18
- package/dist/utils.d.ts +7 -2
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -20461,11 +20461,11 @@ var quotes = collect([
|
|
|
20461
20461
|
]);
|
|
20462
20462
|
var export_prompts = import_prompts.default;
|
|
20463
20463
|
// package.json
|
|
20464
|
-
var version = "0.
|
|
20464
|
+
var version = "0.5.0";
|
|
20465
20465
|
|
|
20466
20466
|
// src/config.ts
|
|
20467
|
-
import
|
|
20468
|
-
import
|
|
20467
|
+
import { homedir } from "os";
|
|
20468
|
+
import { join as join2 } from "path";
|
|
20469
20469
|
|
|
20470
20470
|
// node_modules/bun-config/dist/index.js
|
|
20471
20471
|
import { resolve } from "path";
|
|
@@ -20517,24 +20517,27 @@ async function loadConfig({ name, cwd, defaultConfig }) {
|
|
|
20517
20517
|
}
|
|
20518
20518
|
|
|
20519
20519
|
// src/config.ts
|
|
20520
|
+
var defaultConfig = {
|
|
20521
|
+
from: "localhost:5173",
|
|
20522
|
+
to: "stacks.localhost",
|
|
20523
|
+
https: {
|
|
20524
|
+
basePath: "",
|
|
20525
|
+
caCertPath: join2(homedir(), ".stacks", "ssl", `stacks.localhost.ca.crt`),
|
|
20526
|
+
certPath: join2(homedir(), ".stacks", "ssl", `stacks.localhost.crt`),
|
|
20527
|
+
keyPath: join2(homedir(), ".stacks", "ssl", `stacks.localhost.crt.key`)
|
|
20528
|
+
},
|
|
20529
|
+
etcHostsCleanup: true,
|
|
20530
|
+
verbose: true
|
|
20531
|
+
};
|
|
20520
20532
|
var config4 = await loadConfig({
|
|
20521
20533
|
name: "reverse-proxy",
|
|
20522
|
-
defaultConfig
|
|
20523
|
-
from: "localhost:5173",
|
|
20524
|
-
to: "stacks.localhost",
|
|
20525
|
-
https: {
|
|
20526
|
-
caCertPath: path.join(os2.homedir(), ".stacks", "ssl", `stacks.localhost.ca.crt`),
|
|
20527
|
-
certPath: path.join(os2.homedir(), ".stacks", "ssl", `stacks.localhost.crt`),
|
|
20528
|
-
keyPath: path.join(os2.homedir(), ".stacks", "ssl", `stacks.localhost.crt.key`)
|
|
20529
|
-
},
|
|
20530
|
-
etcHostsCleanup: true,
|
|
20531
|
-
verbose: false
|
|
20532
|
-
}
|
|
20534
|
+
defaultConfig
|
|
20533
20535
|
});
|
|
20534
20536
|
|
|
20535
20537
|
// src/https.ts
|
|
20536
|
-
import
|
|
20537
|
-
import
|
|
20538
|
+
import fs3 from "fs/promises";
|
|
20539
|
+
import { homedir as homedir2 } from "os";
|
|
20540
|
+
import { join as join4 } from "path";
|
|
20538
20541
|
|
|
20539
20542
|
// node_modules/@stacksjs/tlsx/dist/index.js
|
|
20540
20543
|
import fs2 from "fs";
|
|
@@ -20558,7 +20561,7 @@ import {
|
|
|
20558
20561
|
dirname as dirname3,
|
|
20559
20562
|
extname as extname2,
|
|
20560
20563
|
isAbsolute as isAbsolute2,
|
|
20561
|
-
join as
|
|
20564
|
+
join as join3,
|
|
20562
20565
|
normalize as normalize2,
|
|
20563
20566
|
parse as parse2,
|
|
20564
20567
|
relative as relative2,
|
|
@@ -20573,7 +20576,7 @@ import process8 from "process";
|
|
|
20573
20576
|
import process102 from "process";
|
|
20574
20577
|
import process182 from "process";
|
|
20575
20578
|
import process112 from "process";
|
|
20576
|
-
import
|
|
20579
|
+
import os2 from "os";
|
|
20577
20580
|
import tty32 from "tty";
|
|
20578
20581
|
import process142 from "process";
|
|
20579
20582
|
import process132 from "process";
|
|
@@ -20582,11 +20585,11 @@ import process162 from "process";
|
|
|
20582
20585
|
import process172 from "process";
|
|
20583
20586
|
import process192 from "process";
|
|
20584
20587
|
import os22 from "os";
|
|
20585
|
-
import
|
|
20588
|
+
import path from "path";
|
|
20586
20589
|
import { resolve as resolve3 } from "path";
|
|
20587
20590
|
import process22 from "process";
|
|
20588
20591
|
import fs from "fs";
|
|
20589
|
-
import
|
|
20592
|
+
import path2 from "path";
|
|
20590
20593
|
var __create3 = Object.create;
|
|
20591
20594
|
var __getProtoOf3 = Object.getPrototypeOf;
|
|
20592
20595
|
var __defProp3 = Object.defineProperty;
|
|
@@ -48110,29 +48113,29 @@ var log2 = {
|
|
|
48110
48113
|
},
|
|
48111
48114
|
echo: (...args) => console.log(...args)
|
|
48112
48115
|
};
|
|
48113
|
-
function userDatabasePath2(
|
|
48114
|
-
return projectPath2(`database/${
|
|
48116
|
+
function userDatabasePath2(path22) {
|
|
48117
|
+
return projectPath2(`database/${path22 || ""}`);
|
|
48115
48118
|
}
|
|
48116
|
-
function appPath2(
|
|
48117
|
-
return projectPath2(`app/${
|
|
48119
|
+
function appPath2(path22) {
|
|
48120
|
+
return projectPath2(`app/${path22 || ""}`);
|
|
48118
48121
|
}
|
|
48119
|
-
function commandsPath2(
|
|
48120
|
-
return appPath2(`Commands/${
|
|
48122
|
+
function commandsPath2(path22) {
|
|
48123
|
+
return appPath2(`Commands/${path22 || ""}`);
|
|
48121
48124
|
}
|
|
48122
|
-
function logsPath2(
|
|
48123
|
-
return storagePath2(`logs/${
|
|
48125
|
+
function logsPath2(path22) {
|
|
48126
|
+
return storagePath2(`logs/${path22 || ""}`);
|
|
48124
48127
|
}
|
|
48125
48128
|
function projectPath2(filePath = "", options2) {
|
|
48126
|
-
let
|
|
48127
|
-
while (
|
|
48128
|
-
|
|
48129
|
-
const finalPath = resolve22(
|
|
48129
|
+
let path22 = process52.cwd();
|
|
48130
|
+
while (path22.includes("storage"))
|
|
48131
|
+
path22 = resolve22(path22, "..");
|
|
48132
|
+
const finalPath = resolve22(path22, filePath);
|
|
48130
48133
|
if (options2?.relative)
|
|
48131
48134
|
return relative2(process52.cwd(), finalPath);
|
|
48132
48135
|
return finalPath;
|
|
48133
48136
|
}
|
|
48134
|
-
function storagePath2(
|
|
48135
|
-
return projectPath2(`storage/${
|
|
48137
|
+
function storagePath2(path22) {
|
|
48138
|
+
return projectPath2(`storage/${path22 || ""}`);
|
|
48136
48139
|
}
|
|
48137
48140
|
var config6 = {
|
|
48138
48141
|
ai: {
|
|
@@ -54219,7 +54222,7 @@ function _supportsColor2(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
|
|
|
54219
54222
|
return min;
|
|
54220
54223
|
}
|
|
54221
54224
|
if (process112.platform === "win32") {
|
|
54222
|
-
const osRelease =
|
|
54225
|
+
const osRelease = os2.release().split(".");
|
|
54223
54226
|
if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
|
|
54224
54227
|
return Number(osRelease[2]) >= 14931 ? 3 : 2;
|
|
54225
54228
|
}
|
|
@@ -56793,35 +56796,37 @@ function deepMerge2(target, source) {
|
|
|
56793
56796
|
function isObject32(item) {
|
|
56794
56797
|
return Boolean(item && typeof item === "object" && !Array.isArray(item));
|
|
56795
56798
|
}
|
|
56796
|
-
async function loadConfig2({ name, cwd, defaultConfig }) {
|
|
56799
|
+
async function loadConfig2({ name, cwd, defaultConfig: defaultConfig2 }) {
|
|
56797
56800
|
const configPath = resolve3(cwd || process22.cwd(), `${name}.config`);
|
|
56798
56801
|
try {
|
|
56799
56802
|
const importedConfig = await import(configPath);
|
|
56800
56803
|
const loadedConfig = importedConfig.default || importedConfig;
|
|
56801
|
-
return deepMerge2(
|
|
56804
|
+
return deepMerge2(defaultConfig2, loadedConfig);
|
|
56802
56805
|
} catch (error) {
|
|
56803
|
-
return
|
|
56804
|
-
}
|
|
56805
|
-
}
|
|
56806
|
+
return defaultConfig2;
|
|
56807
|
+
}
|
|
56808
|
+
}
|
|
56809
|
+
var defaultConfig2 = {
|
|
56810
|
+
altNameIPs: ["127.0.0.1"],
|
|
56811
|
+
altNameURIs: ["localhost"],
|
|
56812
|
+
organizationName: "Local Development",
|
|
56813
|
+
countryName: "US",
|
|
56814
|
+
stateName: "California",
|
|
56815
|
+
localityName: "Playa Vista",
|
|
56816
|
+
commonName: "stacks.localhost",
|
|
56817
|
+
validityDays: 825,
|
|
56818
|
+
hostCertCN: "stacks.localhost",
|
|
56819
|
+
domain: "stacks.localhost",
|
|
56820
|
+
rootCA: { certificate: "", privateKey: "" },
|
|
56821
|
+
basePath: "",
|
|
56822
|
+
caCertPath: path.join(os22.homedir(), ".stacks", "ssl", `stacks.localhost.ca.crt`),
|
|
56823
|
+
certPath: path.join(os22.homedir(), ".stacks", "ssl", `stacks.localhost.crt`),
|
|
56824
|
+
keyPath: path.join(os22.homedir(), ".stacks", "ssl", `stacks.localhost.crt.key`),
|
|
56825
|
+
verbose: false
|
|
56826
|
+
};
|
|
56806
56827
|
var config42 = await loadConfig2({
|
|
56807
56828
|
name: "tls",
|
|
56808
|
-
defaultConfig:
|
|
56809
|
-
altNameIPs: ["127.0.0.1"],
|
|
56810
|
-
altNameURIs: ["localhost"],
|
|
56811
|
-
organizationName: "Local Development",
|
|
56812
|
-
countryName: "US",
|
|
56813
|
-
stateName: "California",
|
|
56814
|
-
localityName: "Playa Vista",
|
|
56815
|
-
commonName: "stacks.localhost",
|
|
56816
|
-
validityDays: 825,
|
|
56817
|
-
hostCertCN: "stacks.localhost",
|
|
56818
|
-
domain: "stacks.localhost",
|
|
56819
|
-
rootCAObject: { certificate: "", privateKey: "" },
|
|
56820
|
-
caCertPath: path2.join(os22.homedir(), ".stacks", "ssl", `stacks.localhost.ca.crt`),
|
|
56821
|
-
certPath: path2.join(os22.homedir(), ".stacks", "ssl", `stacks.localhost.crt`),
|
|
56822
|
-
keyPath: path2.join(os22.homedir(), ".stacks", "ssl", `stacks.localhost.crt.key`),
|
|
56823
|
-
verbose: false
|
|
56824
|
-
}
|
|
56829
|
+
defaultConfig: defaultConfig2
|
|
56825
56830
|
});
|
|
56826
56831
|
var import_node_forge = __toESM3(require_lib2(), 1);
|
|
56827
56832
|
function makeNumberPositive(hexString) {
|
|
@@ -56837,7 +56842,7 @@ function findFoldersWithFile(rootDir, fileName) {
|
|
|
56837
56842
|
try {
|
|
56838
56843
|
const files = fs.readdirSync(dir);
|
|
56839
56844
|
for (const file of files) {
|
|
56840
|
-
const filePath =
|
|
56845
|
+
const filePath = path2.join(dir, file);
|
|
56841
56846
|
const stats = fs.lstatSync(filePath);
|
|
56842
56847
|
if (stats.isDirectory()) {
|
|
56843
56848
|
search(filePath);
|
|
@@ -56955,12 +56960,12 @@ async function createRootCA(options22 = {}) {
|
|
|
56955
56960
|
async function generateCertificate(options22) {
|
|
56956
56961
|
debugLog("cert", "Generating new certificate", options22.verbose);
|
|
56957
56962
|
debugLog("cert", `Options: ${JSON.stringify(options22)}`, options22.verbose);
|
|
56958
|
-
if (!options22.
|
|
56963
|
+
if (!options22.rootCA?.certificate || !options22.rootCA?.privateKey) {
|
|
56959
56964
|
throw new Error("Root CA certificate and private key are required");
|
|
56960
56965
|
}
|
|
56961
|
-
const caCert = import_node_forge2.pki.certificateFromPem(options22.
|
|
56962
|
-
const caKey = import_node_forge2.pki.privateKeyFromPem(options22.
|
|
56963
|
-
debugLog("cert", "Generating 2048-bit RSA key pair for host certificate", options22
|
|
56966
|
+
const caCert = import_node_forge2.pki.certificateFromPem(options22.rootCA.certificate);
|
|
56967
|
+
const caKey = import_node_forge2.pki.privateKeyFromPem(options22.rootCA.privateKey);
|
|
56968
|
+
debugLog("cert", "Generating 2048-bit RSA key pair for host certificate", options22.verbose);
|
|
56964
56969
|
const keySize = 2048;
|
|
56965
56970
|
const { privateKey, publicKey } = import_node_forge2.pki.rsa.generateKeyPair(keySize);
|
|
56966
56971
|
const attributes = options22.certificateAttributes || [
|
|
@@ -57033,8 +57038,8 @@ async function addCertToSystemTrustStoreAndSaveCert(cert, caCert, options22) {
|
|
|
57033
57038
|
}
|
|
57034
57039
|
function storeCertificate(cert, options22) {
|
|
57035
57040
|
debugLog("storage", `Storing certificate and private key with options: ${JSON.stringify(options22)}`, options22?.verbose);
|
|
57036
|
-
const certPath = options22?.certPath || config42.certPath;
|
|
57037
|
-
const certKeyPath = options22?.keyPath || config42.keyPath;
|
|
57041
|
+
const certPath = path3.join(options22?.basePath || config42.basePath, options22?.certPath || config42.certPath);
|
|
57042
|
+
const certKeyPath = path3.join(options22?.basePath || config42.basePath, options22?.keyPath || config42.keyPath);
|
|
57038
57043
|
debugLog("storage", `Certificate path: ${certPath}`, options22?.verbose);
|
|
57039
57044
|
debugLog("storage", `Private key path: ${certKeyPath}`, options22?.verbose);
|
|
57040
57045
|
const certDir = path3.dirname(certPath);
|
|
@@ -57056,7 +57061,7 @@ function storeCertificate(cert, options22) {
|
|
|
57056
57061
|
}
|
|
57057
57062
|
function storeCACertificate(caCert, options22) {
|
|
57058
57063
|
debugLog("storage", "Storing CA certificate", options22?.verbose);
|
|
57059
|
-
const caCertPath = options22?.caCertPath || config42.caCertPath;
|
|
57064
|
+
const caCertPath = path3.join(options22?.basePath || config42.basePath, options22?.caCertPath || config42.caCertPath);
|
|
57060
57065
|
debugLog("storage", `CA certificate path: ${caCertPath}`, options22?.verbose);
|
|
57061
57066
|
const caCertDir = path3.dirname(caCertPath);
|
|
57062
57067
|
if (!fs2.existsSync(caCertDir)) {
|
|
@@ -57078,114 +57083,172 @@ function debugLog2(category, message, verbose) {
|
|
|
57078
57083
|
console.debug(`[rpx:${category}] ${message}`);
|
|
57079
57084
|
}
|
|
57080
57085
|
}
|
|
57081
|
-
function
|
|
57082
|
-
if (
|
|
57086
|
+
function extractHostname(options3) {
|
|
57087
|
+
if (isMultiProxyOptions(options3)) {
|
|
57083
57088
|
return options3.proxies.map((proxy) => {
|
|
57084
|
-
const
|
|
57085
|
-
return
|
|
57089
|
+
const domain = proxy.to || "stacks.localhost";
|
|
57090
|
+
return domain.startsWith("http") ? new URL(domain).hostname : domain;
|
|
57086
57091
|
});
|
|
57087
57092
|
}
|
|
57088
|
-
|
|
57089
|
-
|
|
57093
|
+
if (isSingleProxyOptions(options3)) {
|
|
57094
|
+
const domain = options3.to || "stacks.localhost";
|
|
57095
|
+
return [domain.startsWith("http") ? new URL(domain).hostname : domain];
|
|
57096
|
+
}
|
|
57097
|
+
return ["stacks.localhost"];
|
|
57098
|
+
}
|
|
57099
|
+
function isValidRootCA(value) {
|
|
57100
|
+
return typeof value === "object" && value !== null && "certificate" in value && "privateKey" in value && typeof value.certificate === "string" && typeof value.privateKey === "string";
|
|
57090
57101
|
}
|
|
57091
57102
|
|
|
57092
57103
|
// src/https.ts
|
|
57093
57104
|
var cachedSSLConfig = null;
|
|
57094
57105
|
function isMultiProxyConfig(options3) {
|
|
57095
|
-
return "proxies" in options3;
|
|
57106
|
+
return "proxies" in options3 && Array.isArray(options3.proxies);
|
|
57107
|
+
}
|
|
57108
|
+
function isMultiProxyOptions(options3) {
|
|
57109
|
+
return "proxies" in options3 && Array.isArray(options3.proxies);
|
|
57110
|
+
}
|
|
57111
|
+
function isSingleProxyOptions(options3) {
|
|
57112
|
+
return "to" in options3 && typeof options3.to === "string";
|
|
57113
|
+
}
|
|
57114
|
+
function resolveSSLPaths(options3, defaultConfig3) {
|
|
57115
|
+
const domain = isMultiProxyConfig(options3) ? options3.proxies[0].to || "stacks.localhost" : options3.to || "stacks.localhost";
|
|
57116
|
+
if (typeof options3.https === "object" && typeof defaultConfig3.https === "object") {
|
|
57117
|
+
const hasAllPaths = options3.https.caCertPath && options3.https.certPath && options3.https.keyPath;
|
|
57118
|
+
if (hasAllPaths) {
|
|
57119
|
+
const baseConfig = httpsConfig({
|
|
57120
|
+
...options3,
|
|
57121
|
+
to: domain,
|
|
57122
|
+
https: defaultConfig3.https
|
|
57123
|
+
});
|
|
57124
|
+
const altNameIPs = options3.https.altNameIPs?.filter((ip) => ip !== undefined) || baseConfig.altNameIPs;
|
|
57125
|
+
const altNameURIs = options3.https.altNameURIs?.filter((uri) => uri !== undefined) || baseConfig.altNameURIs;
|
|
57126
|
+
return {
|
|
57127
|
+
...baseConfig,
|
|
57128
|
+
caCertPath: options3.https.caCertPath || baseConfig.caCertPath,
|
|
57129
|
+
certPath: options3.https.certPath || baseConfig.certPath,
|
|
57130
|
+
keyPath: options3.https.keyPath || baseConfig.keyPath,
|
|
57131
|
+
basePath: options3.https.basePath || baseConfig.basePath,
|
|
57132
|
+
commonName: options3.https.commonName || baseConfig.commonName,
|
|
57133
|
+
organizationName: options3.https.organizationName || baseConfig.organizationName,
|
|
57134
|
+
countryName: options3.https.countryName || baseConfig.countryName,
|
|
57135
|
+
stateName: options3.https.stateName || baseConfig.stateName,
|
|
57136
|
+
localityName: options3.https.localityName || baseConfig.localityName,
|
|
57137
|
+
validityDays: options3.https.validityDays || baseConfig.validityDays,
|
|
57138
|
+
altNameIPs,
|
|
57139
|
+
altNameURIs,
|
|
57140
|
+
verbose: options3.verbose || baseConfig.verbose
|
|
57141
|
+
};
|
|
57142
|
+
}
|
|
57143
|
+
}
|
|
57144
|
+
return httpsConfig({
|
|
57145
|
+
...options3,
|
|
57146
|
+
to: domain
|
|
57147
|
+
});
|
|
57096
57148
|
}
|
|
57097
57149
|
function generateWildcardPatterns(domain) {
|
|
57098
57150
|
const patterns = new Set;
|
|
57099
57151
|
patterns.add(domain);
|
|
57100
57152
|
const parts = domain.split(".");
|
|
57101
|
-
if (parts.length >= 2)
|
|
57153
|
+
if (parts.length >= 2)
|
|
57102
57154
|
patterns.add(`*.${parts.slice(1).join(".")}`);
|
|
57103
|
-
}
|
|
57104
57155
|
return Array.from(patterns);
|
|
57105
57156
|
}
|
|
57106
|
-
function
|
|
57107
|
-
|
|
57108
|
-
|
|
57109
|
-
|
|
57110
|
-
|
|
57111
|
-
|
|
57112
|
-
|
|
57113
|
-
|
|
57114
|
-
|
|
57115
|
-
|
|
57116
|
-
|
|
57117
|
-
|
|
57118
|
-
|
|
57119
|
-
|
|
57120
|
-
|
|
57121
|
-
|
|
57122
|
-
|
|
57123
|
-
|
|
57124
|
-
|
|
57125
|
-
|
|
57126
|
-
|
|
57127
|
-
const
|
|
57128
|
-
debugLog2("ssl", `Generated domain patterns: ${uniqueDomains.join(", ")}`, verbose);
|
|
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
|
+
function generateSSLPaths(options3) {
|
|
57167
|
+
const domain = getPrimaryDomain(options3);
|
|
57168
|
+
let basePath = "";
|
|
57169
|
+
if (typeof options3?.https === "object") {
|
|
57170
|
+
basePath = options3.https.basePath || "";
|
|
57171
|
+
return {
|
|
57172
|
+
caCertPath: options3.https.caCertPath || join4(basePath, `${domain}.ca.crt`),
|
|
57173
|
+
certPath: options3.https.certPath || join4(basePath, `${domain}.crt`),
|
|
57174
|
+
keyPath: options3.https.keyPath || join4(basePath, `${domain}.key`)
|
|
57175
|
+
};
|
|
57176
|
+
}
|
|
57177
|
+
const sslBase = basePath || join4(homedir2(), ".stacks", "ssl");
|
|
57178
|
+
const sanitizedDomain = domain.replace(/\*/g, "wildcard");
|
|
57129
57179
|
return {
|
|
57130
|
-
|
|
57131
|
-
|
|
57132
|
-
|
|
57133
|
-
certPath: httpsConfig?.certPath ?? path4.join(sslBase, "rpx.crt"),
|
|
57134
|
-
keyPath: httpsConfig?.keyPath ?? path4.join(sslBase, "rpx.key"),
|
|
57135
|
-
altNameIPs: httpsConfig?.altNameIPs ?? ["127.0.0.1", "::1"],
|
|
57136
|
-
altNameURIs: httpsConfig?.altNameURIs ?? [],
|
|
57137
|
-
commonName: httpsConfig?.commonName ?? domains[0],
|
|
57138
|
-
organizationName: httpsConfig?.organizationName ?? "Local Development",
|
|
57139
|
-
countryName: httpsConfig?.countryName ?? "US",
|
|
57140
|
-
stateName: httpsConfig?.stateName ?? "California",
|
|
57141
|
-
localityName: httpsConfig?.localityName ?? "Playa Vista",
|
|
57142
|
-
validityDays: httpsConfig?.validityDays ?? 825,
|
|
57143
|
-
verbose: verbose ?? false,
|
|
57144
|
-
subjectAltNames: uniqueDomains.map((domain) => ({
|
|
57145
|
-
type: 2,
|
|
57146
|
-
value: domain
|
|
57147
|
-
}))
|
|
57180
|
+
caCertPath: join4(sslBase, `${sanitizedDomain}.ca.crt`),
|
|
57181
|
+
certPath: join4(sslBase, `${sanitizedDomain}.crt`),
|
|
57182
|
+
keyPath: join4(sslBase, `${sanitizedDomain}.key`)
|
|
57148
57183
|
};
|
|
57149
57184
|
}
|
|
57150
|
-
function
|
|
57151
|
-
const
|
|
57152
|
-
|
|
57153
|
-
|
|
57154
|
-
|
|
57155
|
-
|
|
57156
|
-
|
|
57157
|
-
|
|
57158
|
-
|
|
57159
|
-
|
|
57160
|
-
|
|
57161
|
-
|
|
57162
|
-
|
|
57163
|
-
|
|
57164
|
-
|
|
57165
|
-
|
|
57166
|
-
verbose
|
|
57167
|
-
};
|
|
57185
|
+
function getAllDomains(options3) {
|
|
57186
|
+
const domains = new Set;
|
|
57187
|
+
if (isMultiProxyOptions(options3)) {
|
|
57188
|
+
options3.proxies.forEach((proxy) => {
|
|
57189
|
+
const domain = proxy.to || "stacks.localhost";
|
|
57190
|
+
generateWildcardPatterns(domain).forEach((pattern) => domains.add(pattern));
|
|
57191
|
+
});
|
|
57192
|
+
} else if (isSingleProxyOptions(options3)) {
|
|
57193
|
+
const domain = options3.to || "stacks.localhost";
|
|
57194
|
+
generateWildcardPatterns(domain).forEach((pattern) => domains.add(pattern));
|
|
57195
|
+
} else {
|
|
57196
|
+
domains.add("stacks.localhost");
|
|
57197
|
+
}
|
|
57198
|
+
domains.add("localhost");
|
|
57199
|
+
domains.add("*.localhost");
|
|
57200
|
+
return domains;
|
|
57168
57201
|
}
|
|
57169
|
-
function
|
|
57170
|
-
|
|
57202
|
+
async function loadSSLConfig(options3) {
|
|
57203
|
+
debugLog2("ssl", `Loading SSL configuration`, options3.verbose);
|
|
57204
|
+
const mergedOptions = {
|
|
57205
|
+
...config4,
|
|
57206
|
+
...options3
|
|
57207
|
+
};
|
|
57208
|
+
options3.https = httpsConfig(mergedOptions);
|
|
57209
|
+
if (!options3.https?.keyPath && !options3.https?.certPath) {
|
|
57210
|
+
debugLog2("ssl", "No SSL configuration provided", options3.verbose);
|
|
57211
|
+
return null;
|
|
57212
|
+
}
|
|
57213
|
+
if (options3.https?.keyPath && !options3.https?.certPath || !options3.https?.keyPath && options3.https?.certPath) {
|
|
57214
|
+
const missing = !options3.https?.keyPath ? "keyPath" : "certPath";
|
|
57215
|
+
debugLog2("ssl", `Invalid SSL configuration - missing ${missing}`, options3.verbose);
|
|
57216
|
+
throw new Error(`SSL Configuration requires both keyPath and certPath. Missing: ${missing}`);
|
|
57217
|
+
}
|
|
57218
|
+
try {
|
|
57219
|
+
if (!options3.https?.keyPath || !options3.https?.certPath)
|
|
57220
|
+
return null;
|
|
57221
|
+
try {
|
|
57222
|
+
debugLog2("ssl", "Reading SSL certificate files", options3.verbose);
|
|
57223
|
+
const key = await fs3.readFile(options3.https?.keyPath, "utf8");
|
|
57224
|
+
const cert = await fs3.readFile(options3.https?.certPath, "utf8");
|
|
57225
|
+
debugLog2("ssl", "SSL configuration loaded successfully", options3.verbose);
|
|
57226
|
+
return { key, cert };
|
|
57227
|
+
} catch (error) {
|
|
57228
|
+
debugLog2("ssl", `Failed to read certificates: ${error}`, options3.verbose);
|
|
57229
|
+
return null;
|
|
57230
|
+
}
|
|
57231
|
+
} catch (err3) {
|
|
57232
|
+
debugLog2("ssl", `SSL configuration error: ${err3}`, options3.verbose);
|
|
57233
|
+
throw err3;
|
|
57234
|
+
}
|
|
57171
57235
|
}
|
|
57172
57236
|
async function generateCertificate2(options3) {
|
|
57173
57237
|
if (cachedSSLConfig) {
|
|
57174
|
-
|
|
57175
|
-
debugLog2("ssl", "Using cached SSL configuration", verbose2);
|
|
57238
|
+
debugLog2("ssl", "Using cached SSL configuration", options3.verbose);
|
|
57176
57239
|
return;
|
|
57177
57240
|
}
|
|
57178
|
-
const domains =
|
|
57179
|
-
|
|
57180
|
-
|
|
57181
|
-
const rootCAConfig = generateRootCAConfig(verbose);
|
|
57241
|
+
const domains = isMultiProxyOptions(options3) ? options3.proxies.map((proxy) => proxy.to) : [options3.to];
|
|
57242
|
+
debugLog2("ssl", `Generating certificate for domains: ${domains.join(", ")}`, options3.verbose);
|
|
57243
|
+
const rootCAConfig = httpsConfig(options3, options3.verbose);
|
|
57182
57244
|
log.info("Generating Root CA certificate...");
|
|
57183
57245
|
const caCert = await createRootCA(rootCAConfig);
|
|
57184
|
-
const hostConfig =
|
|
57246
|
+
const hostConfig = httpsConfig(options3, options3.verbose);
|
|
57247
|
+
console.log("hostConfig", hostConfig);
|
|
57185
57248
|
log.info(`Generating host certificate for: ${domains.join(", ")}`);
|
|
57186
57249
|
const hostCert = await generateCertificate({
|
|
57187
57250
|
...hostConfig,
|
|
57188
|
-
|
|
57251
|
+
rootCA: {
|
|
57189
57252
|
certificate: caCert.certificate,
|
|
57190
57253
|
privateKey: caCert.privateKey
|
|
57191
57254
|
}
|
|
@@ -57197,14 +57260,88 @@ async function generateCertificate2(options3) {
|
|
|
57197
57260
|
ca: caCert.certificate
|
|
57198
57261
|
};
|
|
57199
57262
|
log.success(`Certificate generated successfully for ${domains.length} domain${domains.length > 1 ? "s" : ""}`);
|
|
57200
|
-
debugLog2("ssl", `Certificate includes domains: ${domains.join(", ")}`, verbose);
|
|
57263
|
+
debugLog2("ssl", `Certificate includes domains: ${domains.join(", ")}`, options3.verbose);
|
|
57201
57264
|
}
|
|
57202
57265
|
function getSSLConfig() {
|
|
57203
57266
|
return cachedSSLConfig;
|
|
57204
57267
|
}
|
|
57268
|
+
async function checkExistingCertificates(options3) {
|
|
57269
|
+
const name = getPrimaryDomain(options3);
|
|
57270
|
+
const paths = generateSSLPaths(options3);
|
|
57271
|
+
try {
|
|
57272
|
+
debugLog2("ssl", `Checking certificates for ${name} at paths:`, options3?.verbose);
|
|
57273
|
+
debugLog2("ssl", `CA: ${paths.caCertPath}`, options3?.verbose);
|
|
57274
|
+
debugLog2("ssl", `Cert: ${paths.certPath}`, options3?.verbose);
|
|
57275
|
+
debugLog2("ssl", `Key: ${paths.keyPath}`, options3?.verbose);
|
|
57276
|
+
const key = await fs3.readFile(paths.keyPath, "utf8");
|
|
57277
|
+
const cert = await fs3.readFile(paths.certPath, "utf8");
|
|
57278
|
+
let ca;
|
|
57279
|
+
if (paths.caCertPath) {
|
|
57280
|
+
try {
|
|
57281
|
+
ca = await fs3.readFile(paths.caCertPath, "utf8");
|
|
57282
|
+
} catch (err3) {
|
|
57283
|
+
debugLog2("ssl", `Failed to read CA cert: ${err3}`, options3?.verbose);
|
|
57284
|
+
}
|
|
57285
|
+
}
|
|
57286
|
+
return { key, cert, ca };
|
|
57287
|
+
} catch (err3) {
|
|
57288
|
+
debugLog2("ssl", `Failed to read certificates: ${err3}`, options3?.verbose);
|
|
57289
|
+
return null;
|
|
57290
|
+
}
|
|
57291
|
+
}
|
|
57292
|
+
function httpsConfig(options3, verbose) {
|
|
57293
|
+
const primaryDomain = getPrimaryDomain(options3);
|
|
57294
|
+
debugLog2("ssl", `Primary domain: ${primaryDomain}`, verbose);
|
|
57295
|
+
const defaultPaths = generateSSLPaths(options3);
|
|
57296
|
+
if (typeof options3.https === "object") {
|
|
57297
|
+
const config5 = {
|
|
57298
|
+
domain: primaryDomain,
|
|
57299
|
+
hostCertCN: primaryDomain,
|
|
57300
|
+
basePath: options3.https.basePath || "",
|
|
57301
|
+
caCertPath: options3.https.caCertPath || defaultPaths.caCertPath,
|
|
57302
|
+
certPath: options3.https.certPath || defaultPaths.certPath,
|
|
57303
|
+
keyPath: options3.https.keyPath || defaultPaths.keyPath,
|
|
57304
|
+
altNameIPs: ["127.0.0.1", "::1"],
|
|
57305
|
+
altNameURIs: [],
|
|
57306
|
+
commonName: options3.https.commonName || primaryDomain,
|
|
57307
|
+
organizationName: options3.https.organizationName || "Local Development",
|
|
57308
|
+
countryName: options3.https.countryName || "US",
|
|
57309
|
+
stateName: options3.https.stateName || "California",
|
|
57310
|
+
localityName: options3.https.localityName || "Playa Vista",
|
|
57311
|
+
validityDays: options3.https.validityDays || 825,
|
|
57312
|
+
verbose: verbose || false,
|
|
57313
|
+
subjectAltNames: Array.from(getAllDomains(options3)).map((domain) => ({
|
|
57314
|
+
type: 2,
|
|
57315
|
+
value: domain
|
|
57316
|
+
}))
|
|
57317
|
+
};
|
|
57318
|
+
if (isValidRootCA(options3.https.rootCA)) {
|
|
57319
|
+
config5.rootCA = options3.https.rootCA;
|
|
57320
|
+
}
|
|
57321
|
+
return config5;
|
|
57322
|
+
}
|
|
57323
|
+
return {
|
|
57324
|
+
domain: primaryDomain,
|
|
57325
|
+
hostCertCN: primaryDomain,
|
|
57326
|
+
basePath: "",
|
|
57327
|
+
...defaultPaths,
|
|
57328
|
+
altNameIPs: ["127.0.0.1", "::1"],
|
|
57329
|
+
altNameURIs: [],
|
|
57330
|
+
commonName: primaryDomain,
|
|
57331
|
+
organizationName: "Local Development",
|
|
57332
|
+
countryName: "US",
|
|
57333
|
+
stateName: "California",
|
|
57334
|
+
localityName: "Playa Vista",
|
|
57335
|
+
validityDays: 825,
|
|
57336
|
+
verbose: verbose || false,
|
|
57337
|
+
subjectAltNames: Array.from(getAllDomains(options3)).map((domain) => ({
|
|
57338
|
+
type: 2,
|
|
57339
|
+
value: domain
|
|
57340
|
+
}))
|
|
57341
|
+
};
|
|
57342
|
+
}
|
|
57205
57343
|
|
|
57206
57344
|
// src/start.ts
|
|
57207
|
-
import * as fs5 from "fs";
|
|
57208
57345
|
import * as http from "http";
|
|
57209
57346
|
import * as https from "https";
|
|
57210
57347
|
import * as net from "net";
|
|
@@ -57212,29 +57349,29 @@ import process9 from "process";
|
|
|
57212
57349
|
|
|
57213
57350
|
// src/hosts.ts
|
|
57214
57351
|
import { spawn } from "child_process";
|
|
57215
|
-
import
|
|
57216
|
-
import
|
|
57217
|
-
import
|
|
57352
|
+
import fs5 from "fs";
|
|
57353
|
+
import os3 from "os";
|
|
57354
|
+
import path4 from "path";
|
|
57218
57355
|
import process3 from "process";
|
|
57219
|
-
var hostsFilePath = process3.platform === "win32" ?
|
|
57356
|
+
var hostsFilePath = process3.platform === "win32" ? path4.join(process3.env.windir || "C:\\Windows", "System32", "drivers", "etc", "hosts") : "/etc/hosts";
|
|
57220
57357
|
async function sudoWrite(operation, content) {
|
|
57221
57358
|
return new Promise((resolve4, reject) => {
|
|
57222
57359
|
if (process3.platform === "win32") {
|
|
57223
57360
|
reject(new Error("Administrator privileges required on Windows"));
|
|
57224
57361
|
return;
|
|
57225
57362
|
}
|
|
57226
|
-
const tmpFile =
|
|
57363
|
+
const tmpFile = path4.join(os3.tmpdir(), "hosts.tmp");
|
|
57227
57364
|
try {
|
|
57228
57365
|
if (operation === "append") {
|
|
57229
|
-
const currentContent =
|
|
57230
|
-
|
|
57366
|
+
const currentContent = fs5.readFileSync(hostsFilePath, "utf8");
|
|
57367
|
+
fs5.writeFileSync(tmpFile, currentContent + content, "utf8");
|
|
57231
57368
|
} else {
|
|
57232
|
-
|
|
57369
|
+
fs5.writeFileSync(tmpFile, content, "utf8");
|
|
57233
57370
|
}
|
|
57234
57371
|
const sudo = spawn("sudo", ["cp", tmpFile, hostsFilePath]);
|
|
57235
57372
|
sudo.on("close", (code) => {
|
|
57236
57373
|
try {
|
|
57237
|
-
|
|
57374
|
+
fs5.unlinkSync(tmpFile);
|
|
57238
57375
|
if (code === 0)
|
|
57239
57376
|
resolve4();
|
|
57240
57377
|
else
|
|
@@ -57245,7 +57382,7 @@ async function sudoWrite(operation, content) {
|
|
|
57245
57382
|
});
|
|
57246
57383
|
sudo.on("error", (err3) => {
|
|
57247
57384
|
try {
|
|
57248
|
-
|
|
57385
|
+
fs5.unlinkSync(tmpFile);
|
|
57249
57386
|
} catch {
|
|
57250
57387
|
}
|
|
57251
57388
|
reject(err3);
|
|
@@ -57259,7 +57396,7 @@ async function addHosts(hosts, verbose) {
|
|
|
57259
57396
|
debugLog2("hosts", `Adding hosts: ${hosts.join(", ")}`, verbose);
|
|
57260
57397
|
debugLog2("hosts", `Using hosts file at: ${hostsFilePath}`, verbose);
|
|
57261
57398
|
try {
|
|
57262
|
-
const existingContent = await
|
|
57399
|
+
const existingContent = await fs5.promises.readFile(hostsFilePath, "utf-8");
|
|
57263
57400
|
const newEntries = hosts.filter((host) => {
|
|
57264
57401
|
const ipv4Entry = `127.0.0.1 ${host}`;
|
|
57265
57402
|
const ipv6Entry = `::1 ${host}`;
|
|
@@ -57276,7 +57413,7 @@ async function addHosts(hosts, verbose) {
|
|
|
57276
57413
|
::1 ${host}`).join(`
|
|
57277
57414
|
`);
|
|
57278
57415
|
try {
|
|
57279
|
-
await
|
|
57416
|
+
await fs5.promises.appendFile(hostsFilePath, hostEntries, { flag: "a" });
|
|
57280
57417
|
log.success(`Added new hosts: ${newEntries.join(", ")}`);
|
|
57281
57418
|
} catch (writeErr) {
|
|
57282
57419
|
if (writeErr.code === "EACCES") {
|
|
@@ -57314,7 +57451,7 @@ On Unix systems:`);
|
|
|
57314
57451
|
async function removeHosts(hosts, verbose) {
|
|
57315
57452
|
debugLog2("hosts", `Removing hosts: ${hosts.join(", ")}`, verbose);
|
|
57316
57453
|
try {
|
|
57317
|
-
const content = await
|
|
57454
|
+
const content = await fs5.promises.readFile(hostsFilePath, "utf-8");
|
|
57318
57455
|
const lines = content.split(`
|
|
57319
57456
|
`);
|
|
57320
57457
|
const filteredLines = lines.filter((line, index) => {
|
|
@@ -57330,7 +57467,7 @@ async function removeHosts(hosts, verbose) {
|
|
|
57330
57467
|
`)}
|
|
57331
57468
|
`;
|
|
57332
57469
|
try {
|
|
57333
|
-
await
|
|
57470
|
+
await fs5.promises.writeFile(hostsFilePath, newContent);
|
|
57334
57471
|
log.success("Hosts removed successfully");
|
|
57335
57472
|
} catch (writeErr) {
|
|
57336
57473
|
if (writeErr.code === "EACCES") {
|
|
@@ -57370,7 +57507,7 @@ On Unix systems:`);
|
|
|
57370
57507
|
}
|
|
57371
57508
|
async function checkHosts(hosts, verbose) {
|
|
57372
57509
|
debugLog2("hosts", `Checking hosts: ${hosts}`, verbose);
|
|
57373
|
-
const content = await
|
|
57510
|
+
const content = await fs5.promises.readFile(hostsFilePath, "utf-8");
|
|
57374
57511
|
return hosts.map((host) => {
|
|
57375
57512
|
const ipv4Entry = `127.0.0.1 ${host}`;
|
|
57376
57513
|
const ipv6Entry = `::1 ${host}`;
|
|
@@ -57424,39 +57561,6 @@ process9.on("uncaughtException", (err3) => {
|
|
|
57424
57561
|
log.error("Uncaught exception:", err3);
|
|
57425
57562
|
cleanup();
|
|
57426
57563
|
});
|
|
57427
|
-
async function loadSSLConfig(options3) {
|
|
57428
|
-
debugLog2("ssl", `Loading SSL configuration`, options3.verbose);
|
|
57429
|
-
if (options3.https === true)
|
|
57430
|
-
options3.https = httpsConfig(options3);
|
|
57431
|
-
else if (options3.https === false)
|
|
57432
|
-
return null;
|
|
57433
|
-
if (!options3.https?.keyPath && !options3.https?.certPath) {
|
|
57434
|
-
debugLog2("ssl", "No SSL configuration provided", options3.verbose);
|
|
57435
|
-
return null;
|
|
57436
|
-
}
|
|
57437
|
-
if (options3.https?.keyPath && !options3.https?.certPath || !options3.https?.keyPath && options3.https?.certPath) {
|
|
57438
|
-
const missing = !options3.https?.keyPath ? "keyPath" : "certPath";
|
|
57439
|
-
debugLog2("ssl", `Invalid SSL configuration - missing ${missing}`, options3.verbose);
|
|
57440
|
-
throw new Error(`SSL Configuration requires both keyPath and certPath. Missing: ${missing}`);
|
|
57441
|
-
}
|
|
57442
|
-
try {
|
|
57443
|
-
if (!options3.https?.keyPath || !options3.https?.certPath)
|
|
57444
|
-
return null;
|
|
57445
|
-
try {
|
|
57446
|
-
debugLog2("ssl", "Reading SSL certificate files", options3.verbose);
|
|
57447
|
-
const key = await fs5.promises.readFile(options3.https?.keyPath, "utf8");
|
|
57448
|
-
const cert = await fs5.promises.readFile(options3.https?.certPath, "utf8");
|
|
57449
|
-
debugLog2("ssl", "SSL configuration loaded successfully", options3.verbose);
|
|
57450
|
-
return { key, cert };
|
|
57451
|
-
} catch (error) {
|
|
57452
|
-
debugLog2("ssl", `Failed to read certificates: ${error}`, options3.verbose);
|
|
57453
|
-
return null;
|
|
57454
|
-
}
|
|
57455
|
-
} catch (err3) {
|
|
57456
|
-
debugLog2("ssl", `SSL configuration error: ${err3}`, options3.verbose);
|
|
57457
|
-
throw err3;
|
|
57458
|
-
}
|
|
57459
|
-
}
|
|
57460
57564
|
function isPortInUse(port, hostname, verbose) {
|
|
57461
57565
|
debugLog2("port", `Checking if port ${port} is in use on ${hostname}`, verbose);
|
|
57462
57566
|
return new Promise((resolve4) => {
|
|
@@ -57512,8 +57616,8 @@ async function testConnection(hostname, port, verbose) {
|
|
|
57512
57616
|
}
|
|
57513
57617
|
async function startServer(options3) {
|
|
57514
57618
|
debugLog2("server", `Starting server with options: ${JSON.stringify(options3)}`, options3.verbose);
|
|
57515
|
-
const fromUrl = new URL(options3.from
|
|
57516
|
-
const toUrl = new URL(options3.to
|
|
57619
|
+
const fromUrl = new URL((options3.from?.startsWith("http") ? options3.from : `http://${options3.from}`) || "localhost:5173");
|
|
57620
|
+
const toUrl = new URL((options3.to?.startsWith("http") ? options3.to : `http://${options3.to}`) || "stacks.localhost");
|
|
57517
57621
|
const fromPort = Number.parseInt(fromUrl.port) || (fromUrl.protocol.includes("https:") ? 443 : 80);
|
|
57518
57622
|
const hostsToCheck = [toUrl.hostname];
|
|
57519
57623
|
if (!toUrl.hostname.includes("localhost") && !toUrl.hostname.includes("127.0.0.1")) {
|
|
@@ -57597,7 +57701,7 @@ async function startServer(options3) {
|
|
|
57597
57701
|
debugLog2("server", `Setting up reverse proxy with SSL config for ${toUrl.hostname}`, options3.verbose);
|
|
57598
57702
|
await setupReverseProxy({
|
|
57599
57703
|
...options3,
|
|
57600
|
-
from: options3.from,
|
|
57704
|
+
from: options3.from || "localhost:5173",
|
|
57601
57705
|
to: toUrl.hostname,
|
|
57602
57706
|
fromPort,
|
|
57603
57707
|
sourceUrl: {
|
|
@@ -57752,51 +57856,77 @@ function startHttpRedirectServer(verbose) {
|
|
|
57752
57856
|
debugLog2("redirect", "HTTP redirect server started", verbose);
|
|
57753
57857
|
}
|
|
57754
57858
|
function startProxy(options3) {
|
|
57755
|
-
|
|
57859
|
+
const mergedOptions = {
|
|
57860
|
+
...config4,
|
|
57861
|
+
...options3
|
|
57862
|
+
};
|
|
57863
|
+
debugLog2("proxy", `Starting proxy with options: ${JSON.stringify(mergedOptions)}`, mergedOptions?.verbose);
|
|
57756
57864
|
const serverOptions = {
|
|
57757
|
-
from:
|
|
57758
|
-
to:
|
|
57759
|
-
https: httpsConfig(
|
|
57760
|
-
etcHostsCleanup:
|
|
57761
|
-
verbose:
|
|
57865
|
+
from: mergedOptions.from,
|
|
57866
|
+
to: mergedOptions.to,
|
|
57867
|
+
https: httpsConfig(mergedOptions),
|
|
57868
|
+
etcHostsCleanup: mergedOptions.etcHostsCleanup,
|
|
57869
|
+
verbose: mergedOptions.verbose
|
|
57762
57870
|
};
|
|
57763
57871
|
console.log("serverOptions", serverOptions);
|
|
57764
57872
|
startServer(serverOptions).catch((err3) => {
|
|
57765
|
-
debugLog2("proxy", `Failed to start proxy: ${err3}`,
|
|
57873
|
+
debugLog2("proxy", `Failed to start proxy: ${err3}`, mergedOptions.verbose);
|
|
57766
57874
|
log.error(`Failed to start proxy: ${err3.message}`);
|
|
57767
57875
|
cleanup({
|
|
57768
|
-
domains: [
|
|
57769
|
-
etcHostsCleanup:
|
|
57770
|
-
verbose:
|
|
57876
|
+
domains: [mergedOptions.to],
|
|
57877
|
+
etcHostsCleanup: mergedOptions.etcHostsCleanup,
|
|
57878
|
+
verbose: mergedOptions.verbose
|
|
57771
57879
|
});
|
|
57772
57880
|
});
|
|
57773
57881
|
}
|
|
57774
57882
|
async function startProxies(options3) {
|
|
57775
|
-
|
|
57776
|
-
|
|
57777
|
-
|
|
57778
|
-
|
|
57779
|
-
|
|
57883
|
+
debugLog2("proxies", "Starting proxy setup", options3?.verbose);
|
|
57884
|
+
const mergedOptions = {
|
|
57885
|
+
...config4,
|
|
57886
|
+
...options3
|
|
57887
|
+
};
|
|
57888
|
+
const primaryDomain = isMultiProxyConfig(mergedOptions) ? mergedOptions.proxies[0].to || "stacks.localhost" : mergedOptions.to || "stacks.localhost";
|
|
57889
|
+
if (mergedOptions.https) {
|
|
57890
|
+
const existingSSLConfig = await checkExistingCertificates(mergedOptions);
|
|
57891
|
+
if (existingSSLConfig) {
|
|
57892
|
+
debugLog2("ssl", `Using existing certificates for ${primaryDomain}`, mergedOptions.verbose);
|
|
57893
|
+
mergedOptions._cachedSSLConfig = existingSSLConfig;
|
|
57894
|
+
} else {
|
|
57895
|
+
debugLog2("ssl", `No valid certificates found for ${primaryDomain}, generating new ones`, mergedOptions.verbose);
|
|
57896
|
+
await generateCertificate2(mergedOptions);
|
|
57897
|
+
const sslConfig2 = await checkExistingCertificates(mergedOptions);
|
|
57898
|
+
if (!sslConfig2) {
|
|
57899
|
+
throw new Error(`Failed to load SSL certificates after generation for ${primaryDomain}. Please check file permissions and paths.`);
|
|
57900
|
+
}
|
|
57901
|
+
mergedOptions._cachedSSLConfig = sslConfig2;
|
|
57902
|
+
}
|
|
57780
57903
|
}
|
|
57781
|
-
const proxyOptions =
|
|
57904
|
+
const proxyOptions = isMultiProxyConfig(mergedOptions) ? mergedOptions.proxies.map((proxy) => ({
|
|
57782
57905
|
...proxy,
|
|
57783
|
-
https:
|
|
57784
|
-
etcHostsCleanup:
|
|
57785
|
-
verbose:
|
|
57786
|
-
_cachedSSLConfig:
|
|
57787
|
-
})) : [
|
|
57788
|
-
|
|
57789
|
-
|
|
57906
|
+
https: mergedOptions.https,
|
|
57907
|
+
etcHostsCleanup: mergedOptions.etcHostsCleanup,
|
|
57908
|
+
verbose: mergedOptions.verbose,
|
|
57909
|
+
_cachedSSLConfig: mergedOptions._cachedSSLConfig
|
|
57910
|
+
})) : [{
|
|
57911
|
+
from: mergedOptions.from || "localhost:5173",
|
|
57912
|
+
to: mergedOptions.to || "stacks.localhost",
|
|
57913
|
+
https: mergedOptions.https,
|
|
57914
|
+
etcHostsCleanup: mergedOptions.etcHostsCleanup,
|
|
57915
|
+
verbose: mergedOptions.verbose,
|
|
57916
|
+
_cachedSSLConfig: mergedOptions._cachedSSLConfig
|
|
57917
|
+
}];
|
|
57918
|
+
const domains = proxyOptions.map((opt) => opt.to || "stacks.localhost");
|
|
57919
|
+
const sslConfig = mergedOptions._cachedSSLConfig;
|
|
57790
57920
|
const cleanupHandler = () => cleanup({
|
|
57791
57921
|
domains,
|
|
57792
|
-
etcHostsCleanup:
|
|
57793
|
-
verbose:
|
|
57922
|
+
etcHostsCleanup: mergedOptions.etcHostsCleanup || false,
|
|
57923
|
+
verbose: mergedOptions.verbose || false
|
|
57794
57924
|
});
|
|
57795
57925
|
process9.on("SIGINT", cleanupHandler);
|
|
57796
57926
|
process9.on("SIGTERM", cleanupHandler);
|
|
57797
57927
|
process9.on("uncaughtException", (err3) => {
|
|
57798
57928
|
debugLog2("process", `Uncaught exception: ${err3}`, true);
|
|
57799
|
-
|
|
57929
|
+
console.error("Uncaught exception:", err3);
|
|
57800
57930
|
cleanupHandler();
|
|
57801
57931
|
});
|
|
57802
57932
|
for (const option of proxyOptions) {
|
|
@@ -57813,14 +57943,11 @@ async function startProxies(options3) {
|
|
|
57813
57943
|
});
|
|
57814
57944
|
} catch (err3) {
|
|
57815
57945
|
debugLog2("proxies", `Failed to start proxy for ${option.to}: ${err3}`, option.verbose);
|
|
57816
|
-
|
|
57946
|
+
console.error(`Failed to start proxy for ${option.to}:`, err3);
|
|
57817
57947
|
cleanupHandler();
|
|
57818
57948
|
}
|
|
57819
57949
|
}
|
|
57820
57950
|
}
|
|
57821
|
-
function isMultiProxyConfig2(options3) {
|
|
57822
|
-
return "proxies" in options3;
|
|
57823
|
-
}
|
|
57824
57951
|
|
|
57825
57952
|
// bin/cli.ts
|
|
57826
57953
|
var cli = new CAC("reverse-proxy");
|