mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-07-16 21:33:41 +00:00
8b6037b7ff
- ssh/ renamed to hosts/ (it covers SSH, RDP, VNC, Telnet, Docker, metrics) - serial/serial.ts and guacamole/ moved inside hosts/ - dashboard.ts and homepage.ts moved to services/ - swagger.ts moved to utils/ with adjusted scan globs Import paths and the generate:openapi script updated; ports and endpoints unchanged.
71 lines
1.7 KiB
TypeScript
71 lines
1.7 KiB
TypeScript
import express from "express";
|
|
import cookieParser from "cookie-parser";
|
|
import { createCorsMiddleware } from "../../utils/cors-config.js";
|
|
import { logger } from "../../utils/logger.js";
|
|
import { AuthManager } from "../../utils/auth-manager.js";
|
|
import { registerDockerContainerRoutes } from "./container-routes.js";
|
|
import {
|
|
sshSessions,
|
|
pendingTOTPSessions,
|
|
cleanupSession,
|
|
executeDockerCommand,
|
|
} from "./session-manager.js";
|
|
import {
|
|
DOCKER_TIMESTAMP_RE,
|
|
getRequestUserId,
|
|
registerDockerSshRoutes,
|
|
} from "./routes.js";
|
|
|
|
const sshLogger = logger;
|
|
|
|
const app = express();
|
|
|
|
app.use(createCorsMiddleware(["GET", "POST", "PUT", "DELETE", "OPTIONS"]));
|
|
|
|
app.use(cookieParser());
|
|
app.use(express.json({ limit: "100mb" }));
|
|
app.use(express.urlencoded({ limit: "100mb", extended: true }));
|
|
app.use((_req, res, next) => {
|
|
res.setHeader("Cache-Control", "no-store");
|
|
next();
|
|
});
|
|
|
|
const authManager = AuthManager.getInstance();
|
|
app.use(authManager.createAuthMiddleware());
|
|
|
|
registerDockerSshRoutes(app);
|
|
|
|
registerDockerContainerRoutes(app, {
|
|
sshSessions,
|
|
pendingTOTPSessions,
|
|
getRequestUserId,
|
|
executeDockerCommand,
|
|
dockerTimestampPattern: DOCKER_TIMESTAMP_RE,
|
|
});
|
|
|
|
const PORT = 30007;
|
|
|
|
app.listen(PORT, async () => {
|
|
try {
|
|
await authManager.initialize();
|
|
} catch (err) {
|
|
sshLogger.error("Failed to initialize Docker backend", err, {
|
|
operation: "startup",
|
|
});
|
|
}
|
|
});
|
|
|
|
process.on("SIGINT", () => {
|
|
Object.keys(sshSessions).forEach((sessionId) => {
|
|
cleanupSession(sessionId);
|
|
});
|
|
process.exit(0);
|
|
});
|
|
|
|
process.on("SIGTERM", () => {
|
|
Object.keys(sshSessions).forEach((sessionId) => {
|
|
cleanupSession(sessionId);
|
|
});
|
|
process.exit(0);
|
|
});
|