import { requestJson } from "./startup.js" import { GxNotice } from "./notice.js" export const ReverseProxySettings = { components: { GxNotice }, props: { unauthorized: Function, mode: String }, data: () => ({ status: null, enabled: false, address: "", origin: "", busy: false, error: "", saved: false }), mounted() { if (this.mode === "local") this.load() }, methods: { async load() { try { const data = await requestJson("./api/connect/proxy") this.status = data this.enabled = data.enabled this.address = data.address this.origin = data.origin } catch (error) { this.failed(error) } }, failed(error) { if (error.status === 401) this.unauthorized() else this.error = error.message || "Reverse proxy settings are unavailable" }, async save() { if (this.busy || !this.status?.canEdit) return if (!window.confirm(this.enabled ? "Allow this proxy and HTTPS origin? Proxy access requires your Galaxy password." : "Disable reverse proxy access? Direct IP access will remain available.")) return this.busy = true this.error = "" this.saved = false try { this.status = await requestJson("./api/connect/proxy", { request: { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ enabled: this.enabled, address: this.address.trim(), origin: this.origin.trim(), revision: this.status.revision, confirmed: true }) } }) this.saved = true } catch (error) { this.failed(error) } finally { this.busy = false } }, }, template: `
Reverse proxy
Turn off the vehicle to change reverse proxy settings. Configure a Galaxy password on the device before enabling reverse proxy access. Reverse proxy settings saved. {{ error }}
`, }