mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-22 20:08:46 +00:00
refactor(wss): simplify container ID validation and update Docker command structure
This commit is contained in:
@@ -3,7 +3,7 @@ import { findServerById, IS_CLOUD, validateRequest } from "@dokploy/server";
|
|||||||
import { spawn } from "node-pty";
|
import { spawn } from "node-pty";
|
||||||
import { Client } from "ssh2";
|
import { Client } from "ssh2";
|
||||||
import { WebSocketServer } from "ws";
|
import { WebSocketServer } from "ws";
|
||||||
import { getShell, isValidContainerId, isValidShell } from "./utils";
|
import { isValidContainerId, isValidShell } from "./utils";
|
||||||
|
|
||||||
export const setupDockerContainerTerminalWebSocketServer = (
|
export const setupDockerContainerTerminalWebSocketServer = (
|
||||||
server: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>,
|
server: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>,
|
||||||
@@ -34,11 +34,6 @@ export const setupDockerContainerTerminalWebSocketServer = (
|
|||||||
const serverId = url.searchParams.get("serverId");
|
const serverId = url.searchParams.get("serverId");
|
||||||
const { user, session } = await validateRequest(req);
|
const { user, session } = await validateRequest(req);
|
||||||
|
|
||||||
if (!containerId) {
|
|
||||||
ws.close(4000, "containerId no provided");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!containerId) {
|
if (!containerId) {
|
||||||
ws.close(4000, "containerId not provided");
|
ws.close(4000, "containerId not provided");
|
||||||
return;
|
return;
|
||||||
@@ -150,10 +145,9 @@ export const setupDockerContainerTerminalWebSocketServer = (
|
|||||||
ws.close();
|
ws.close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const shell = getShell();
|
|
||||||
const ptyProcess = spawn(
|
const ptyProcess = spawn(
|
||||||
shell,
|
"docker",
|
||||||
["-c", `docker exec -it -w / ${containerId} ${activeWay}`],
|
["exec", "-it", "-w", "/", containerId, shell],
|
||||||
{},
|
{},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user