mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-28 06:05:24 +00:00
fix: use the vite proxy for plugin sockets on any dev port
This commit is contained in:
1 parent
3a851ad189
commit
e166994ec4
3 files changed
+21
-5
No files matched your search
@@ -20,7 +20,9 @@ export function getDatabaseTransferUrl(
|
|||||||
return `${serverUrl.replace(/\/$/, "")}/database/${operation}`;
|
return `${serverUrl.replace(/\/$/, "")}/database/${operation}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const development = location.port === "5173";
|
// Vite moves off 5173 when another dev server holds it.
|
||||||
|
const development =
|
||||||
|
process.env.NODE_ENV === "development" || location.port === "5173";
|
||||||
|
|
||||||
if (development) {
|
if (development) {
|
||||||
return `http://localhost:30001/database/${operation}`;
|
return `http://localhost:30001/database/${operation}`;
|
||||||
|
|||||||
@@ -175,11 +175,10 @@ export async function pluginWsUrl(
|
|||||||
const protocols = websocketAuthProtocols(token);
|
const protocols = websocketAuthProtocols(token);
|
||||||
|
|
||||||
// Dev without a configured API host goes through Vite's proxy, which is
|
// Dev without a configured API host goes through Vite's proxy, which is
|
||||||
// reached on the page's own origin rather than the backend port.
|
// reached on the page's own origin rather than the backend port. Vite moves
|
||||||
|
// to another port when 5173 is taken, so the port says nothing here.
|
||||||
const devProxy =
|
const devProxy =
|
||||||
process.env.NODE_ENV === "development" &&
|
process.env.NODE_ENV === "development" && !import.meta.env.VITE_API_HOST;
|
||||||
!import.meta.env.VITE_API_HOST &&
|
|
||||||
(window.location.port === "3000" || window.location.port === "5173");
|
|
||||||
|
|
||||||
const wsProtocol = window.location.protocol === "https:" ? "wss" : "ws";
|
const wsProtocol = window.location.protocol === "https:" ? "wss" : "ws";
|
||||||
|
|
||||||
|
|||||||
@@ -111,6 +111,21 @@ describe("pluginWsUrl in the browser", () => {
|
|||||||
expect(target?.protocols).toEqual(["termix.jwt.ticket-1"]);
|
expect(target?.protocols).toEqual(["termix.jwt.ticket-1"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("goes through the Vite proxy in dev on any port", async () => {
|
||||||
|
vi.stubEnv("NODE_ENV", "development");
|
||||||
|
try {
|
||||||
|
fetchMock.mockResolvedValueOnce(
|
||||||
|
new Response(JSON.stringify({ ticket: "ticket-1" })),
|
||||||
|
);
|
||||||
|
const target = await pluginWsUrl("ssh-terminal", "/terminal");
|
||||||
|
expect(target?.url).toBe(
|
||||||
|
`ws://${window.location.host}/__termix_api/30001/plugin-ws/ssh-terminal/terminal`,
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
vi.unstubAllEnvs();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
it("falls back to the cookie alone for a guest", async () => {
|
it("falls back to the cookie alone for a guest", async () => {
|
||||||
fetchMock.mockResolvedValueOnce(new Response("{}", { status: 401 }));
|
fetchMock.mockResolvedValueOnce(new Response("{}", { status: 401 }));
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user