gateway: MAGPIE_PUBLIC_URL at a private address is the local network's, the Docker bridge's other containers', alike in Connect's menu
jiezhengj (Discord) runs magpie in Docker on a NAS, MAGPIE_PUBLIC_URL at the NAS's own 192.168.31.218. The web UI's Gateway list called that address "Public address" (公网地址), which reads as the internet's, and Connect's Base URL menu offered 本机 / 公网地址 / 局域网, where 局域网 was really the Docker bridge's 172.17.0.1 that other containers on the host use, while the list above it named that one "Other containers on this host". The classification itself was right (gateway.PublicIP never takes RFC 1918, CGNAT or ULA for the internet); the labels weren't: any MAGPIE_PUBLIC_URL was "Public address", and Connect's menu had its own three-way rule that knew nothing of the bridge or of internet addresses. - gateway.URLKind(u): "internet" (PublicIP), "local" (any other IP literal) or "" (a name, not looked up). /api/settings and /api/providers' gateway carry it as publicKind beside publicURL. - settings.js addrWho(g, u, others) is the one rule: this computer; the bridge address as other containers'; an internet address as such; MAGPIE_PUBLIC_URL by its kind (private: Local network; a name: Public address); anything else Local network. The Gateway list (each label said once for the lines it heads; local, then other containers, then internet), Connect's Base URL menu and About's MAGPIE_PUBLIC_URL row all use it. - "Public address" now only names a MAGPIE_PUBLIC_URL that is a host name; zh 公网地址 → 对外地址, zh-TW 公開位址 → 對外位址 (ja/de already neutral enough: 公開アドレス, Öffentliche Adresse). No new strings. Run, on mote (sandbox HOME, Go 1.26.8): - go test -run 'URLKind|PublicURL|LAN|Container|DefaultGateway|HostNetwork' ./internal/gateway ./internal/gui: ok, at2dac9b84eand again at this rebased head on6b7ee4a98(then rebased ontoa7113d5c9, which shares no file with this, and not run again). - GUI, chromium and webkit, 18 files (allow-ips, api-key-theme, connect-snippet-shell, gateway-card, gateway-connect-keys, gateway-caller-keys, connect-address-kept, gateway-keys-off, lan-public, lan-docker, phone-connect-menu, public-url, public-url-default, side-gateway-lan, key-page, statusline-remote, i18n-keys, i18n-en-no-cjk): chromium 152/156, webkit 153/156. Every red is red at base2dac9b84etoo and filed: i18n-keys "a plugin's words are its own" (#5332, #5327, #5482, #5426), phone-connect-menu 420 public / no public URL (#4706, #4707), gateway-caller-keys chromium en (#3797, passed at base this time). - Again at this rebased head: lan-docker, public-url-default, public-url, lan-public in both engines, 86/86. - gofmt -l clean; go vet darwin (gateway, gui, cli), GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./...: ok. - Full go test -tags nogui -timeout 45m ./... through suite.lock was still running at push (the owner's rule: no verified commit waits on the queue); a red it shows gets its own issue. Broken by hand: TestPublicURLSaysItsKind on the old source fails "publicKind <nil>, want local" (and want internet); the new lan-docker test with the old JS fails 'Public address' vs 'Local network' and '公网地址' vs '局域网' (chromium en, zh). Not tried: - a real Docker container or NAS; the cases are fixtures. - magpie web's and the share banner's CLI lines still say "network" for every address, internet ones too; left alone. - an in-container page opened at a public IP the host derived (not in lanPublic, not MAGPIE_PUBLIC_URL) is still labelled Local network. - ja/de "Public address" wording kept. Reported-by: jiezhengj on Discord
This commit is contained in:
@@ -326,6 +326,27 @@ func PublicIP(ip net.IP) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// URLKind is what u's host is: "internet" for an address anyone online
|
||||
// may reach (PublicIP), "local" for any other IP address (a home or
|
||||
// office network's, Tailscale's, a Docker network's), and "" for a name,
|
||||
// which magpie doesn't look up. MAGPIE_PUBLIC_URL is often a private one:
|
||||
// a NAS's 192.168.31.218, which the GUI called "Public address" (公网地址)
|
||||
// beside the 172.17.0.1 other containers on it use (jiezhengj on Discord).
|
||||
func URLKind(u string) string {
|
||||
p, err := url.Parse(u)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
ip := net.ParseIP(p.Hostname())
|
||||
switch {
|
||||
case ip == nil:
|
||||
return ""
|
||||
case PublicIP(ip):
|
||||
return "internet"
|
||||
}
|
||||
return "local"
|
||||
}
|
||||
|
||||
// PublicURLs are those of urls (LANURLs) at an internet address.
|
||||
func PublicURLs(urls []string) []string {
|
||||
var out []string
|
||||
|
||||
@@ -459,3 +459,25 @@ func TestDefaultGateway(t *testing.T) {
|
||||
t.Errorf("not in a container: %q, want none", got)
|
||||
}
|
||||
}
|
||||
|
||||
// A private network's address is never called the internet's: RFC 1918's
|
||||
// (a NAS's 192.168.31.218, Docker's 172.17.0.1), Tailscale's, IPv6's own
|
||||
// private range. A name isn't looked up.
|
||||
func TestURLKind(t *testing.T) {
|
||||
for u, want := range map[string]string{
|
||||
"http://192.168.31.218:3425": "local",
|
||||
"http://172.17.0.1:3425": "local",
|
||||
"http://10.0.0.5:3425": "local",
|
||||
"http://100.101.102.103:3425": "local",
|
||||
"http://[fd12:3456::1]:3425": "local",
|
||||
"http://203.0.113.9:3425": "internet",
|
||||
"http://[2001:4860::8888]:3425": "internet",
|
||||
"https://magpie.example.com": "",
|
||||
"http://nas.local:3425": "",
|
||||
"": "",
|
||||
} {
|
||||
if got := URLKind(u); got != want {
|
||||
t.Errorf("URLKind(%q) = %q, want %q", u, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -403,6 +403,10 @@ type settingsJSON struct {
|
||||
// gateway, shown beside the local address agents here are pointed at
|
||||
// (#1551)
|
||||
PublicURL string `json:"publicURL,omitempty"`
|
||||
// PublicKind is gateway.URLKind's of PublicURL: "local" (a private
|
||||
// network's address), "internet", or "" for a name; the page names
|
||||
// it by that, not as public whatever it is
|
||||
PublicKind string `json:"publicKind,omitempty"`
|
||||
// MAGPIE_ADDR, when it sets the gateway's address over Settings' port
|
||||
AddrEnv string `json:"addrEnv,omitempty"`
|
||||
// MAGPIE_ALLOW_IPS, when it sets the allow list over Settings', and
|
||||
@@ -792,6 +796,7 @@ func settingsState() settingsJSON {
|
||||
}
|
||||
if s.LAN || gateway.OnNetwork() {
|
||||
s.PublicURL = gateway.PublicURL()
|
||||
s.PublicKind = gateway.URLKind(s.PublicURL)
|
||||
}
|
||||
s.WSL = runtime.GOOS == "windows"
|
||||
s.Web = webPage.Load()
|
||||
|
||||
@@ -20088,8 +20088,14 @@ function renderSettings() {
|
||||
const cmd = "curl -fsS -m 1 -H 'Authorization: Bearer <gateway key>' --data-binary @- " + gw + "/v1/magpie/statusline || true";
|
||||
row(t("Status line on another computer"), t("statusLine's command in Claude Code's settings.json there; a read-only gateway key is enough"), cmd, copyBtn(cmd, t("Command"))).id = "statuslineRemoteRow";
|
||||
}
|
||||
// MAGPIE_PUBLIC_URL, where other machines reach it (#1551)
|
||||
if (s.publicURL && gw !== s.publicURL) row(t("Public address"), t("MAGPIE_PUBLIC_URL: where other computers reach the gateway, with a gateway key"), s.publicURL, copyBtn(s.publicURL, t("Public address"))).id = "publicURLRow";
|
||||
// MAGPIE_PUBLIC_URL, where other machines reach it (#1551), named as
|
||||
// the Gateway page names it (addrWho): a private address is the local
|
||||
// network's, not "Public address" (jiezhengj on Discord)
|
||||
if (s.publicURL && gw !== s.publicURL) {
|
||||
const who = self.addrWho?.({ url: s.gateway, publicURL: s.publicURL, publicKind: s.publicKind, lanPublic: s.lanPublic }, s.publicURL,
|
||||
s.lanContainerHost ? [s.lanContainerHost] : []) || t("Public address");
|
||||
row(who, t("MAGPIE_PUBLIC_URL: where other computers reach the gateway, with a gateway key"), s.publicURL, copyBtn(s.publicURL, who)).id = "publicURLRow";
|
||||
}
|
||||
const site = el("button", "text", t("Open"));
|
||||
site.onclick = () => api("open", { url: "https://usemagpie.ai" }).catch(() => {});
|
||||
row(t("Website"), t("downloads, docs and what's new"), "usemagpie.ai", site);
|
||||
|
||||
@@ -1139,7 +1139,7 @@ const I18N = {
|
||||
"Instead of masking, send to": "命中脱敏时改用",
|
||||
"A key goes as a made-up one of the same form (sk_… stays sk_…), not a placeholder, and comes back as it was": "密钥以同样格式的虚构密钥发出(sk_… 仍是 sk_…),而非占位符,回来时还原",
|
||||
"Local network": "局域网",
|
||||
"Public address": "公网地址",
|
||||
"Public address": "对外地址",
|
||||
"MAGPIE_PUBLIC_URL: where other computers reach the gateway, with a gateway key": "MAGPIE_PUBLIC_URL:其他电脑访问网关的地址,需带网关密钥",
|
||||
"Share on local network": "局域网共享",
|
||||
"Gateway address": "网关地址",
|
||||
@@ -5821,7 +5821,7 @@ const I18N = {
|
||||
"Instead of masking, send to": "命中脫敏時改用",
|
||||
"A key goes as a made-up one of the same form (sk_… stays sk_…), not a placeholder, and comes back as it was": "金鑰以同樣格式的虛構金鑰送出(sk_… 仍是 sk_…),而非佔位符,回來時還原",
|
||||
"Local network": "區域網",
|
||||
"Public address": "公開位址",
|
||||
"Public address": "對外位址",
|
||||
"MAGPIE_PUBLIC_URL: where other computers reach the gateway, with a gateway key": "MAGPIE_PUBLIC_URL:其他電腦連到閘道的位址,需帶閘道金鑰",
|
||||
"Share on local network": "區域網共享",
|
||||
"Gateway address": "閘道位址",
|
||||
|
||||
@@ -276,17 +276,17 @@ function renderGatewayLan() {
|
||||
// the one they reach, MAGPIE_PUBLIC_URL's, not this computer's loopback
|
||||
// (#1551)
|
||||
const shown = web && g.publicURL || g.url;
|
||||
line(t(shown === g.url ? "This computer" : "Public address"), shown);
|
||||
const { urls, others, sub } = gwLAN(g);
|
||||
line(addrWho(g, shown, others), shown);
|
||||
if (g.lan) {
|
||||
const { urls, others, sub } = gwLAN(g);
|
||||
// an internet address on an interface (an ISP's static one) is said
|
||||
// to be one, not listed as this network's, and the one other
|
||||
// containers on this host use (the host's Docker bridge address) is
|
||||
// said to be theirs
|
||||
const far = new Set(g.lanPublic || []), rest = urls.filter((u) => u !== shown);
|
||||
rest.filter((u) => !far.has(u) && !others.includes(u)).forEach((u, i) => line(i ? "" : t("Local network"), u));
|
||||
rest.filter((u) => others.includes(u)).forEach((u, i) => line(i ? "" : t("Other containers on this host"), u));
|
||||
rest.filter((u) => far.has(u) && !others.includes(u)).forEach((u, i) => line(i ? "" : t("On the internet"), u));
|
||||
// each address named as Connect's menu names it (addrWho): this
|
||||
// network's first, then the one other containers on this host use
|
||||
// (the host's Docker bridge address), then one on the internet (an
|
||||
// ISP's static one); a name said once for the lines it heads
|
||||
const said = [addrWho(g, shown, others)], rest = urls.filter((u) => u !== shown);
|
||||
const order = [t("Local network"), t("Public address"), t("Other containers on this host"), t("On the internet")];
|
||||
rest.map((u) => [addrWho(g, u, others), u]).sort((a, b) => order.indexOf(a[0]) - order.indexOf(b[0]))
|
||||
.forEach(([who, u]) => { line(said.at(-1) === who ? "" : who, u); said.push(who); });
|
||||
if (!urls.length) list.append(el("div", "gw-url-none", t("This computer has no local network address right now")));
|
||||
if (sub) list.append(el("div", "gw-url-none", sub));
|
||||
}
|
||||
@@ -545,7 +545,7 @@ function renderConnect() {
|
||||
|
||||
const b = el("div", "val");
|
||||
if (urls.length > 1) b.append(connectPick("connectAddress", "Address", base,
|
||||
urls.map((u) => ({ v: u, name: f.base(u), note: t(u === g.url ? "This computer" : u === g.publicURL ? "Public address" : "Local network") })), connectURL,
|
||||
urls.map((u) => ({ v: u, name: f.base(u), note: addrWho(g, u, gwLAN(g).others) })), connectURL,
|
||||
(u) => { connectWant = u; keepPick("magpie.connectAddress", u); renderConnect(); }));
|
||||
else b.append(el("code", "", base));
|
||||
b.append(copyBtn(base, "Base URL"));
|
||||
|
||||
@@ -300,6 +300,20 @@ function lanShown(urls, container, bridge) {
|
||||
function gwLAN(g) {
|
||||
return lanShown(g?.lan && g.lanURLs || [], !!g?.container, g?.lan && g.containerHost || "");
|
||||
}
|
||||
// addrWho: the words every list of the gateway's addresses names one by,
|
||||
// for g (providers' gateway, or Settings' read as one): this computer's,
|
||||
// the one other containers on this host use, one on the internet, and
|
||||
// MAGPIE_PUBLIC_URL by its kind, a private address being the local
|
||||
// network's like the rest. jiezhengj on Discord: Connect called the NAS's
|
||||
// 192.168.31.218 "Public address" (公网地址) and the Docker bridge's
|
||||
// 172.17.0.1 "Local network", while the list above it said otherwise.
|
||||
function addrWho(g, u, others = []) {
|
||||
if (u === g.url) return t("This computer");
|
||||
if (others.includes(u)) return t("Other containers on this host");
|
||||
if ((g.lanPublic || []).includes(u) || u === g.publicURL && g.publicKind === "internet") return t("On the internet");
|
||||
if (u === g.publicURL && g.publicKind !== "local") return t("Public address");
|
||||
return t("Local network");
|
||||
}
|
||||
// gwFar: where other machines reach the gateway, for the sidebar and the
|
||||
// key page: other containers' address only when there is no other
|
||||
function gwFar(g) {
|
||||
|
||||
@@ -549,6 +549,9 @@ type gatewayJSON struct {
|
||||
// PublicURL is MAGPIE_PUBLIC_URL when it is among LANURLs: Connect
|
||||
// starts there until the user picks an address (#1551)
|
||||
PublicURL string `json:"publicURL,omitempty"`
|
||||
// PublicKind is gateway.URLKind's of PublicURL, which Connect and
|
||||
// the list above it name it by
|
||||
PublicKind string `json:"publicKind,omitempty"`
|
||||
// LANPublic are those of LANURLs at an internet address, which anyone
|
||||
// online reaches, not only this network
|
||||
LANPublic []string `json:"lanPublic,omitempty"`
|
||||
@@ -1212,7 +1215,7 @@ func providersState() providersJSON {
|
||||
s.Gateway.LANPublic = gateway.PublicURLs(s.Gateway.LANURLs)
|
||||
s.Gateway.Container, s.Gateway.ContainerHost = gateway.ContainerAddrs(), gateway.ContainerHostURL()
|
||||
if u := gateway.PublicURL(); slices.Contains(s.Gateway.LANURLs, u) {
|
||||
s.Gateway.PublicURL = u
|
||||
s.Gateway.PublicURL, s.Gateway.PublicKind = u, gateway.URLKind(u)
|
||||
}
|
||||
}
|
||||
for _, e := range cat {
|
||||
|
||||
@@ -142,3 +142,45 @@ func TestPublicURLOnlyWhereOffered(t *testing.T) {
|
||||
t.Errorf("no MAGPIE_PUBLIC_URL: Settings shows %q", u)
|
||||
}
|
||||
}
|
||||
|
||||
// jiezhengj on Discord: magpie in Docker on a NAS, MAGPIE_PUBLIC_URL at
|
||||
// the NAS's 192.168.31.218, and the page called it "Public address"
|
||||
// (公网地址) as if anyone online reached it. Settings and the Gateway page
|
||||
// say what kind of address it is, and a private one is the local
|
||||
// network's.
|
||||
func TestPublicURLSaysItsKind(t *testing.T) {
|
||||
h := t.TempDir()
|
||||
testenv.SetHome(t, h)
|
||||
t.Setenv("XDG_CONFIG_HOME", filepath.Join(h, ".config"))
|
||||
t.Setenv("XDG_CACHE_HOME", filepath.Join(h, ".cache"))
|
||||
t.Setenv("XDG_DATA_HOME", filepath.Join(h, ".local", "share"))
|
||||
t.Setenv("MAGPIE_ADDR", "127.0.0.1:3425")
|
||||
if err := settings.Save(settings.Settings{LAN: true}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
kind := func(v any) any {
|
||||
b, err := json.Marshal(v)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var m map[string]any
|
||||
if err := json.Unmarshal(b, &m); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return m["publicKind"]
|
||||
}
|
||||
for u, want := range map[string]any{
|
||||
"http://192.168.31.218:3425": "local",
|
||||
"http://172.17.0.1:3425": "local",
|
||||
"http://203.0.113.9:3425": "internet",
|
||||
"https://magpie.example.com": nil,
|
||||
} {
|
||||
t.Setenv("MAGPIE_PUBLIC_URL", u)
|
||||
if got := kind(providersState().Gateway); got != want {
|
||||
t.Errorf("%s: Gateway page's publicKind %v, want %v", u, got, want)
|
||||
}
|
||||
if got := kind(settingsState()); got != want {
|
||||
t.Errorf("%s: Settings' publicKind %v, want %v", u, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1962,7 +1962,11 @@ the OpenAI/Anthropic switch keeps that host and doesn't move the page. Opened
|
||||
at localhost, the container's address stays and the row says it is the
|
||||
container's own and to set `MAGPIE_PUBLIC_URL`. Outside a container nothing
|
||||
changes. No coloured left border; English and Chinese, Chromium and WebKit,
|
||||
with `/api/plugins` faked.
|
||||
with `/api/plugins` faked. With `MAGPIE_PUBLIC_URL` at the NAS's private
|
||||
192.168.31.218 (jiezhengj on Discord), the Gateway page's list, Connect's
|
||||
menu and About name it the local network's, not "Public address", and the
|
||||
Docker bridge's 172.17.0.1 other containers'; an internet address is named
|
||||
the internet's. Every language, at 1100 and 420 wide.
|
||||
|
||||
`routing-time.test.cjs` checks a routing group's rule for hours of the day
|
||||
(Discord: send a provider's peak-price hours, DeepSeek's or GLM's, to
|
||||
@@ -2114,7 +2118,7 @@ with nothing shared), and a network address that needs an enabled gateway
|
||||
key. English and Chinese, Chromium and WebKit, with `/api/plugins` faked.
|
||||
|
||||
`public-url-default.test.cjs` checks that Connect starts at MAGPIE_PUBLIC_URL,
|
||||
labelled Public address, with the snippets on it, until an address is
|
||||
labelled Public address (对外地址) when it is a name, with the snippets on it, until an address is
|
||||
picked, and that a pick (this computer's) is kept after a reload (#1551).
|
||||
About shows the public URL beside the local one; magpie web shows it as the
|
||||
gateway's address and the MCP server's, the app keeps those local. Without
|
||||
|
||||
+4
-2
@@ -28,8 +28,10 @@ function fixture(lang, theme, events, options = {}) {
|
||||
const lanURLs = options.lanURLs || ["http://192.168.1.10:3999", "http://10.0.0.10:3999"];
|
||||
// options.lanPublic are those of them at an internet address
|
||||
const lanPublic = () => lan && options.lanPublic ? { lanPublic: options.lanPublic } : {};
|
||||
// options.publicURL is MAGPIE_PUBLIC_URL's, offered while shared (#1551)
|
||||
const publicURL = () => lan && options.publicURL ? { publicURL: options.publicURL } : {};
|
||||
// options.publicURL is MAGPIE_PUBLIC_URL's, offered while shared (#1551),
|
||||
// and options.publicKind what kind of address it is (gateway.URLKind)
|
||||
const publicURL = () => lan && options.publicURL ? { publicURL: options.publicURL,
|
||||
...(options.publicKind ? { publicKind: options.publicKind } : {}) } : {};
|
||||
// options.container: magpie runs in a container, and lanURLs are its
|
||||
// own; options.containerHost is where other containers on the host
|
||||
// reach the gateway (the host's Docker bridge address)
|
||||
|
||||
@@ -20,7 +20,7 @@ const fs = require("node:fs/promises");
|
||||
const path = require("node:path");
|
||||
const { test } = require("node:test");
|
||||
const { chromium, webkit } = require("playwright");
|
||||
const { watchSettingsReads, settingsDrawn } = require("./reader.cjs");
|
||||
const { watchSettingsReads, settingsDrawn, openPart } = require("./reader.cjs");
|
||||
const { fixture } = require("./fixtures/caller-keys.cjs");
|
||||
|
||||
const assets = path.resolve(__dirname, "../assets");
|
||||
@@ -65,18 +65,18 @@ const words = {
|
||||
opened: "Other devices use the host’s address this page was opened at, and other containers on this host the host’s Docker bridge address, both on the gateway’s port; MAGPIE_PUBLIC_URL sets another",
|
||||
bridge: "Other containers on this host use the host’s Docker bridge address, on the gateway’s port; other devices use the host’s own, which MAGPIE_PUBLIC_URL puts here",
|
||||
own: "The container’s own addresses, which other devices can’t reach: set MAGPIE_PUBLIC_URL to the host’s",
|
||||
others: "Other containers on this host", lan: "Local network",
|
||||
others: "Other containers on this host", lan: "Local network", here: "This computer",
|
||||
},
|
||||
zh: {
|
||||
container: "在容器中运行",
|
||||
opened: "其他设备用打开这个页面所用的宿主机地址,本机上的其他容器用宿主机的 Docker bridge 地址,端口都是网关的端口;MAGPIE_PUBLIC_URL 可另设",
|
||||
bridge: "本机上的其他容器用宿主机的 Docker bridge 地址,端口是网关的端口;其他设备用宿主机自己的地址,用 MAGPIE_PUBLIC_URL 把它设在这里",
|
||||
own: "容器自身的地址,其他设备无法访问:请将 MAGPIE_PUBLIC_URL 设为宿主机地址",
|
||||
others: "同一主机上的其他容器", lan: "局域网",
|
||||
others: "同一主机上的其他容器", lan: "局域网", here: "本机",
|
||||
},
|
||||
"zh-TW": { others: "同一主機上的其他容器", lan: "區域網" },
|
||||
ja: { others: "同じホストのほかのコンテナ", lan: "ローカルネットワーク" },
|
||||
de: { others: "Andere Container auf diesem Host", lan: "Lokales Netzwerk" },
|
||||
"zh-TW": { others: "同一主機上的其他容器", lan: "區域網", here: "本機" },
|
||||
ja: { others: "同じホストのほかのコンテナ", lan: "ローカルネットワーク", here: "このコンピュータ" },
|
||||
de: { others: "Andere Container auf diesem Host", lan: "Lokales Netzwerk", here: "Dieser Computer" },
|
||||
};
|
||||
const BRIDGE = "http://172.17.0.1:3425";
|
||||
|
||||
@@ -237,3 +237,85 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// jiezhengj on Discord: magpie in Docker on a NAS, MAGPIE_PUBLIC_URL at the
|
||||
// NAS's own 192.168.31.218. The list on the Gateway page called it "Public
|
||||
// address" (公网地址), as if anyone online reached it, and Connect's menu
|
||||
// called the Docker bridge's 172.17.0.1 "Local network" while the list
|
||||
// called it other containers'. A private address is the local network's,
|
||||
// the bridge's is other containers', in the list, in Connect's menu and in
|
||||
// About alike; a public one is the internet's.
|
||||
const NAS = "http://192.168.31.218:3999";
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) {
|
||||
for (const width of [1100, 420]) {
|
||||
test(`${engine} ${lang} ${width}: MAGPIE_PUBLIC_URL at a private address is the local network's, the bridge other containers'`, async (t) => {
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
t.after(() => browser.close());
|
||||
const w = words[lang];
|
||||
const open = async (at, web, over = {}) => {
|
||||
const page = await (await browser.newContext({ viewport: { width, height: 800 }, reducedMotion: "reduce" })).newPage();
|
||||
await page.addInitScript(() => { try { localStorage.setItem("magpie.gwConnectFolded", "0"); } catch {} });
|
||||
page.setDefaultTimeout(6000);
|
||||
page.setDefaultNavigationTimeout(60000);
|
||||
const errors = [];
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.route("**/*", fixture(lang, "light", [], { lan: true, web, containerHost: HOSTBR, // MAGPIE_PUBLIC_URL says the host's: no container's own addresses
|
||||
lanURLs: [NAS], publicURL: NAS, publicKind: "local", ...over }));
|
||||
await page.goto(at + "/?view=gateway");
|
||||
await page.locator("#gatewayLan .gw-url").first().waitFor();
|
||||
await page.locator("#connectAddress").waitFor();
|
||||
return { page, errors };
|
||||
};
|
||||
const list = async (page) => {
|
||||
const rows = page.locator("#gatewayLan .gw-url");
|
||||
const out = [];
|
||||
for (let i = 0; i < await rows.count(); i++)
|
||||
out.push([(await rows.nth(i).locator(".gw-url-label").textContent()).trim(), (await rows.nth(i).locator("code").textContent()).trim()]);
|
||||
return out;
|
||||
};
|
||||
const menu = async (page) => {
|
||||
await page.locator("#connectAddress").click();
|
||||
const items = page.locator(".proto-menu .pm-item");
|
||||
await items.first().waitFor();
|
||||
const names = (await items.locator(".pm-name").allTextContents()).map((x) => x.trim());
|
||||
const notes = (await items.locator(".pm-note").allTextContents()).map((x) => x.trim());
|
||||
return names.map((n, i) => [notes[i], n]);
|
||||
};
|
||||
const fits = async (page) => assert.equal(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth), true, "wider than the window");
|
||||
|
||||
// magpie web, opened at the NAS: the list and Connect's menu name
|
||||
// each address the same way
|
||||
{
|
||||
const { page, errors } = await open("http://192.168.31.218:3430", true);
|
||||
assert.deepEqual(await list(page), [[w.lan, NAS], [w.others, HOSTBR]]);
|
||||
assert.deepEqual(await menu(page), [[w.here, "http://127.0.0.1:3999/v1"], [w.lan, NAS + "/v1"], [w.others, HOSTBR + "/v1"]]);
|
||||
await fits(page);
|
||||
assert.deepEqual(errors, []);
|
||||
}
|
||||
// the app on the NAS: About names it as the Gateway page does
|
||||
{
|
||||
const { page, errors } = await open("http://magpie.test", false);
|
||||
assert.deepEqual(await list(page), [[w.here, "http://127.0.0.1:3999"], [w.lan, NAS], [w.others, HOSTBR]]);
|
||||
await page.keyboard.press("Escape");
|
||||
await page.locator("#prefs").click();
|
||||
await openPart(page, "about");
|
||||
await page.locator("#publicURLRow").waitFor();
|
||||
assert.equal((await page.locator("#publicURLRow .who .name").textContent()).trim(), w.lan);
|
||||
await fits(page);
|
||||
assert.deepEqual(errors, []);
|
||||
}
|
||||
// an internet address is the internet's, in the list and the menu
|
||||
{
|
||||
const PUB = "http://203.0.113.9:3999";
|
||||
const { page, errors } = await open("http://203.0.113.9:3430", true, { containerHost: "",
|
||||
lanURLs: [PUB], publicURL: PUB, publicKind: "internet", lanPublic: [PUB] });
|
||||
const internet = await page.evaluate(() => t("On the internet"));
|
||||
assert.deepEqual(await list(page), [[internet, PUB]]);
|
||||
assert.deepEqual(await menu(page), [[w.here, "http://127.0.0.1:3999/v1"], [internet, PUB + "/v1"]]);
|
||||
assert.deepEqual(errors, []);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ const PUBLIC = "https://magpie.example.com";
|
||||
const LOCAL = "http://127.0.0.1:3999";
|
||||
const LANGS = ["en", "zh", "zh-TW", "ja", "de"];
|
||||
const words = {
|
||||
en: "Public address", zh: "公网地址", "zh-TW": "公開位址", ja: "公開アドレス", de: "Öffentliche Adresse",
|
||||
en: "Public address", zh: "对外地址", "zh-TW": "對外位址", ja: "公開アドレス", de: "Öffentliche Adresse",
|
||||
};
|
||||
|
||||
async function setup(t, engine, lang, width, options) {
|
||||
|
||||
Reference in New Issue
Block a user