Wizard: preserve QuickStart gateway settings
This commit is contained in:
@@ -133,16 +133,94 @@ export async function runOnboardingWizard(
|
|||||||
flow = "advanced";
|
flow = "advanced";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const quickstartGateway = (() => {
|
||||||
|
const hasExisting =
|
||||||
|
typeof baseConfig.gateway?.port === "number" ||
|
||||||
|
baseConfig.gateway?.bind !== undefined ||
|
||||||
|
baseConfig.gateway?.auth?.mode !== undefined ||
|
||||||
|
baseConfig.gateway?.auth?.token !== undefined ||
|
||||||
|
baseConfig.gateway?.auth?.password !== undefined ||
|
||||||
|
baseConfig.gateway?.tailscale?.mode !== undefined;
|
||||||
|
|
||||||
|
const bindRaw = baseConfig.gateway?.bind;
|
||||||
|
const bind =
|
||||||
|
bindRaw === "loopback" ||
|
||||||
|
bindRaw === "lan" ||
|
||||||
|
bindRaw === "tailnet" ||
|
||||||
|
bindRaw === "auto"
|
||||||
|
? bindRaw
|
||||||
|
: "loopback";
|
||||||
|
|
||||||
|
let authMode: GatewayAuthChoice = "off";
|
||||||
|
if (
|
||||||
|
baseConfig.gateway?.auth?.mode === "token" ||
|
||||||
|
baseConfig.gateway?.auth?.mode === "password"
|
||||||
|
) {
|
||||||
|
authMode = baseConfig.gateway.auth.mode;
|
||||||
|
} else if (baseConfig.gateway?.auth?.token) {
|
||||||
|
authMode = "token";
|
||||||
|
} else if (baseConfig.gateway?.auth?.password) {
|
||||||
|
authMode = "password";
|
||||||
|
}
|
||||||
|
|
||||||
|
const tailscaleRaw = baseConfig.gateway?.tailscale?.mode;
|
||||||
|
const tailscaleMode =
|
||||||
|
tailscaleRaw === "off" ||
|
||||||
|
tailscaleRaw === "serve" ||
|
||||||
|
tailscaleRaw === "funnel"
|
||||||
|
? tailscaleRaw
|
||||||
|
: "off";
|
||||||
|
|
||||||
|
return {
|
||||||
|
hasExisting,
|
||||||
|
port: resolveGatewayPort(baseConfig),
|
||||||
|
bind,
|
||||||
|
authMode,
|
||||||
|
tailscaleMode,
|
||||||
|
token: baseConfig.gateway?.auth?.token,
|
||||||
|
password: baseConfig.gateway?.auth?.password,
|
||||||
|
tailscaleResetOnExit: baseConfig.gateway?.tailscale?.resetOnExit ?? false,
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
|
||||||
if (flow === "quickstart") {
|
if (flow === "quickstart") {
|
||||||
|
const formatBind = (value: "loopback" | "lan" | "tailnet" | "auto") => {
|
||||||
|
if (value === "loopback") return "Loopback (127.0.0.1)";
|
||||||
|
if (value === "lan") return "LAN";
|
||||||
|
if (value === "tailnet") return "Tailnet";
|
||||||
|
return "Auto";
|
||||||
|
};
|
||||||
|
const formatAuth = (value: GatewayAuthChoice) => {
|
||||||
|
if (value === "off") return "Off (loopback only)";
|
||||||
|
if (value === "token") return "Token";
|
||||||
|
return "Password";
|
||||||
|
};
|
||||||
|
const formatTailscale = (value: "off" | "serve" | "funnel") => {
|
||||||
|
if (value === "off") return "Off";
|
||||||
|
if (value === "serve") return "Serve";
|
||||||
|
return "Funnel";
|
||||||
|
};
|
||||||
|
const quickstartLines = quickstartGateway.hasExisting
|
||||||
|
? [
|
||||||
|
"Keeping your current gateway settings:",
|
||||||
|
`Gateway port: ${quickstartGateway.port}`,
|
||||||
|
`Gateway bind: ${formatBind(quickstartGateway.bind)}`,
|
||||||
|
`Gateway auth: ${formatAuth(quickstartGateway.authMode)}`,
|
||||||
|
`Tailscale exposure: ${formatTailscale(
|
||||||
|
quickstartGateway.tailscaleMode,
|
||||||
|
)}`,
|
||||||
|
"Direct to chat providers.",
|
||||||
|
]
|
||||||
|
: [
|
||||||
|
`Gateway port: ${DEFAULT_GATEWAY_PORT}`,
|
||||||
|
"Gateway bind: Loopback (127.0.0.1)",
|
||||||
|
"Gateway auth: Off (loopback only)",
|
||||||
|
"Tailscale exposure: Off",
|
||||||
|
"Direct to chat providers.",
|
||||||
|
];
|
||||||
await prompter.note(
|
await prompter.note(
|
||||||
[
|
quickstartLines.join("\n"),
|
||||||
"Gateway port: 18789",
|
"QuickStart",
|
||||||
"Gateway bind: Loopback (127.0.0.1)",
|
|
||||||
"Gateway auth: Off (loopback only)",
|
|
||||||
"Tailscale exposure: Off",
|
|
||||||
"Direct to chat providers.",
|
|
||||||
].join("\n"),
|
|
||||||
"QuickStart defaults",
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,7 +326,7 @@ export async function runOnboardingWizard(
|
|||||||
|
|
||||||
const port =
|
const port =
|
||||||
flow === "quickstart"
|
flow === "quickstart"
|
||||||
? DEFAULT_GATEWAY_PORT
|
? quickstartGateway.port
|
||||||
: Number.parseInt(
|
: Number.parseInt(
|
||||||
String(
|
String(
|
||||||
await prompter.text({
|
await prompter.text({
|
||||||
@@ -263,7 +341,7 @@ export async function runOnboardingWizard(
|
|||||||
|
|
||||||
let bind = (
|
let bind = (
|
||||||
flow === "quickstart"
|
flow === "quickstart"
|
||||||
? "loopback"
|
? quickstartGateway.bind
|
||||||
: ((await prompter.select({
|
: ((await prompter.select({
|
||||||
message: "Gateway bind",
|
message: "Gateway bind",
|
||||||
options: [
|
options: [
|
||||||
@@ -277,7 +355,7 @@ export async function runOnboardingWizard(
|
|||||||
|
|
||||||
let authMode = (
|
let authMode = (
|
||||||
flow === "quickstart"
|
flow === "quickstart"
|
||||||
? "off"
|
? quickstartGateway.authMode
|
||||||
: ((await prompter.select({
|
: ((await prompter.select({
|
||||||
message: "Gateway auth",
|
message: "Gateway auth",
|
||||||
options: [
|
options: [
|
||||||
@@ -298,7 +376,7 @@ export async function runOnboardingWizard(
|
|||||||
|
|
||||||
const tailscaleMode = (
|
const tailscaleMode = (
|
||||||
flow === "quickstart"
|
flow === "quickstart"
|
||||||
? "off"
|
? quickstartGateway.tailscaleMode
|
||||||
: ((await prompter.select({
|
: ((await prompter.select({
|
||||||
message: "Tailscale exposure",
|
message: "Tailscale exposure",
|
||||||
options: [
|
options: [
|
||||||
@@ -317,7 +395,8 @@ export async function runOnboardingWizard(
|
|||||||
})) as "off" | "serve" | "funnel")
|
})) as "off" | "serve" | "funnel")
|
||||||
) as "off" | "serve" | "funnel";
|
) as "off" | "serve" | "funnel";
|
||||||
|
|
||||||
let tailscaleResetOnExit = false;
|
let tailscaleResetOnExit =
|
||||||
|
flow === "quickstart" ? quickstartGateway.tailscaleResetOnExit : false;
|
||||||
if (tailscaleMode !== "off" && flow !== "quickstart") {
|
if (tailscaleMode !== "off" && flow !== "quickstart") {
|
||||||
await prompter.note(
|
await prompter.note(
|
||||||
[
|
[
|
||||||
@@ -358,19 +437,26 @@ export async function runOnboardingWizard(
|
|||||||
|
|
||||||
let gatewayToken: string | undefined;
|
let gatewayToken: string | undefined;
|
||||||
if (authMode === "token") {
|
if (authMode === "token") {
|
||||||
const tokenInput = await prompter.text({
|
if (flow === "quickstart" && quickstartGateway.token) {
|
||||||
message: "Gateway token (blank to generate)",
|
gatewayToken = quickstartGateway.token;
|
||||||
placeholder: "Needed for multi-machine or non-loopback access",
|
} else {
|
||||||
initialValue: randomToken(),
|
const tokenInput = await prompter.text({
|
||||||
});
|
message: "Gateway token (blank to generate)",
|
||||||
gatewayToken = String(tokenInput).trim() || randomToken();
|
placeholder: "Needed for multi-machine or non-loopback access",
|
||||||
|
initialValue: quickstartGateway.token ?? randomToken(),
|
||||||
|
});
|
||||||
|
gatewayToken = String(tokenInput).trim() || randomToken();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (authMode === "password") {
|
if (authMode === "password") {
|
||||||
const password = await prompter.text({
|
const password =
|
||||||
message: "Gateway password",
|
flow === "quickstart" && quickstartGateway.password
|
||||||
validate: (value) => (value?.trim() ? undefined : "Required"),
|
? quickstartGateway.password
|
||||||
});
|
: await prompter.text({
|
||||||
|
message: "Gateway password",
|
||||||
|
validate: (value) => (value?.trim() ? undefined : "Required"),
|
||||||
|
});
|
||||||
nextConfig = {
|
nextConfig = {
|
||||||
...nextConfig,
|
...nextConfig,
|
||||||
gateway: {
|
gateway: {
|
||||||
|
|||||||
Reference in New Issue
Block a user