fix: keep localhost database export same-origin (#1112)

This commit is contained in:
ZacharyZcR
2026-07-28 01:48:27 +08:00
committed by GitHub
parent 50372cb25f
commit 3f33961657
2 changed files with 18 additions and 4 deletions
+1 -4
View File
@@ -20,10 +20,7 @@ export function getDatabaseTransferUrl(
return `${serverUrl.replace(/\/$/, "")}/database/${operation}`; return `${serverUrl.replace(/\/$/, "")}/database/${operation}`;
} }
const development = const development = location.port === "5173";
location.port === "5173" ||
location.hostname === "localhost" ||
location.hostname === "127.0.0.1";
if (development) { if (development) {
return `http://localhost:30001/database/${operation}`; return `http://localhost:30001/database/${operation}`;
@@ -51,4 +51,21 @@ describe("getDatabaseTransferUrl", () => {
}), }),
).toBe("http://localhost:30001/database/export"); ).toBe("http://localhost:30001/database/export");
}); });
it.each(["localhost", "127.0.0.1"])(
"keeps Docker access through %s on the browser origin",
(hostname) => {
expect(
getDatabaseTransferUrl("export", {
electron: false,
location: {
protocol: "http:",
host: `${hostname}:8080`,
hostname,
port: "8080",
},
}),
).toBe(`http://${hostname}:8080/database/export`);
},
);
}); });