支持可配置反代HTTPS端口并统一管理与重置入口

This commit is contained in:
xuans committed 2026-09-17 22:44:19 +08:00
1 parent b2b8951bcf
commit 54b19a19f8
23 files changed
+268 -50

No files matched your search

+1 -1
View File
@@ -365,7 +365,7 @@ export function useDashboard() {
function createEmptySettingsForm() {
return {
server: { host: "", port: 5200, https_mode: "direct" },
server: { host: "", port: 5200, https_mode: "direct", proxy_https_port: 0 },
web: { enabled: true, hostname: "", public_ip: "" },
paths: { certificate: "" },
acme: {
@@ -439,6 +439,10 @@ const {
</div>
<div class="form-grid">
<label class="field"><span>HTTPS 模式</span><select v-model="settingsForm.server.https_mode"><option value="direct">直接终止 HTTPS</option><option value="proxy">反向代理 HTTPS</option></select></label>
<label v-if="settingsForm.server.https_mode === 'proxy'" class="field">
<span>代理公开 HTTPS 端口(0 为默认 443)</span>
<input v-model.number="settingsForm.server.proxy_https_port" type="number" min="0" max="65535" required />
</label>
<label class="field"><span>证书存储路径</span><input v-model="settingsForm.paths.certificate" required /></label>
</div>
<div class="form-grid">
@@ -18,6 +18,7 @@ export function bootstrapPayload(legacy, databaseToken, environment) {
web_public_ip: legacy.web_public_ip,
web_enabled: legacy.web_enabled,
https_mode: legacy.https_mode,
proxy_https_port: legacy.proxy_https_port,
acme_environment: environment,
propagation_timeout_secs: legacy.propagation_timeout_secs,
propagation_polling_interval_secs: legacy.propagation_polling_interval_secs,
@@ -109,6 +109,7 @@ export function useSetupWizard(props, emit) {
web_public_ip: props.status.web_public_ip || "",
web_enabled: props.status.web_enabled !== false,
https_mode: props.status.https_mode || "direct",
proxy_https_port: props.status.proxy_https_port || 443,
acme_environment: props.status.acme_environment || "staging",
});
@@ -673,6 +674,13 @@ export function useSetupWizard(props, emit) {
}
if (currentStep.value === 4) {
if (form.value.https_mode === "proxy") {
const port = Number(form.value.proxy_https_port);
if (!Number.isInteger(port) || port < 1 || port > 65535) {
error.value = "代理公开 HTTPS 端口必须为 1 至 65535 的整数。";
return false;
}
}
if (!form.value.certificate_root.trim()) {
error.value = "请填写证书部署根目录。";
return false;
@@ -804,6 +812,7 @@ export function useSetupWizard(props, emit) {
web_public_ip: publicIP,
web_enabled: form.value.web_enabled,
https_mode: form.value.https_mode,
proxy_https_port: form.value.https_mode === "proxy" ? Number(form.value.proxy_https_port) : 0,
})),
});
const result = await response.json().catch(() => ({}));
@@ -913,6 +913,18 @@ const {
</option>
</select>
</label>
<label v-if="form.https_mode === 'proxy'">
<span>代理公开 HTTPS 端口</span>
<input
id="proxy-https-port"
name="proxy_https_port"
v-model.number="form.proxy_https_port"
type="number"
min="1"
max="65535"
required
/>
</label>
</div>
<label class="confirm-row">
<input
@@ -7,6 +7,29 @@ function completion() {
return Response.json({ completed: true, management_url: "https://203.0.113.20:8443/" });
}
test("代理模式提交公开端口并跳转至对应入口", async (t) => {
const address = "https://admin.example.test:8004/";
const { state, submitted, emitted } = await setup(t, () => Response.json({ completed: true, management_url: address }));
state.form.value.https_mode = "proxy";
state.form.value.proxy_https_port = 8004;
state.currentStep.value = 4;
await state.handleSubmit();
assert.equal(submitted[0].proxy_https_port, 8004);
assert.equal(emitted.at(-1)[1].management_url, address);
});
for (const port of [0, -1, 65536, 8004.5, ""]) {
test(`代理模式拒绝非法公开端口 ${port}`, async (t) => {
const { state, submitted } = await setup(t);
state.form.value.https_mode = "proxy";
state.form.value.proxy_https_port = port;
state.currentStep.value = 4;
await state.handleSubmit();
assert.equal(submitted.length, 0);
assert.match(state.error.value, /代理公开 HTTPS 端口/);
});
}
async function setup(t, complete = completion, driver = "sqlite") {
const submitted = [];
const emitted = [];