mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-29 14:45:24 +00:00
feat: serve plugin http and websockets from one mount instead of ports
This commit is contained in:
1 parent
c496a093ca
commit
8431570ff7
102 files changed
+2894
-2308
No files matched your search
@@ -1,8 +1,14 @@
|
||||
import { SystemCrypto } from "./system-crypto.js";
|
||||
import { pluginEvents, TOPICS } from "../plugins/events.js";
|
||||
import { sshLogger } from "./logger.js";
|
||||
|
||||
const METRICS_SERVICE_URL = "http://localhost:30005";
|
||||
|
||||
/**
|
||||
* Announces an SSH login so anything watching can react to it.
|
||||
*
|
||||
* Was an HTTP POST to the metrics service on localhost:30005. Host metrics is
|
||||
* a plugin now and has no port, so this publishes on the plugin event bus and
|
||||
* the plugin subscribes. Fire and forget: a subscriber that throws must never
|
||||
* fail the login that caused it.
|
||||
*/
|
||||
export async function dispatchLoginEvent(
|
||||
hostId: number,
|
||||
userId: string,
|
||||
@@ -10,24 +16,7 @@ export async function dispatchLoginEvent(
|
||||
fromIp: string,
|
||||
): Promise<void> {
|
||||
try {
|
||||
const token = await SystemCrypto.getInstance().getInternalAuthToken();
|
||||
const response = await fetch(
|
||||
`${METRICS_SERVICE_URL}/internal/login-alert`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"x-internal-auth": token,
|
||||
},
|
||||
body: JSON.stringify({ hostId, userId, sshUser, fromIp }),
|
||||
},
|
||||
);
|
||||
if (!response.ok) {
|
||||
const details = await response.text();
|
||||
throw new Error(
|
||||
`Metrics service returned ${response.status}${details ? `: ${details}` : ""}`,
|
||||
);
|
||||
}
|
||||
pluginEvents.emit(TOPICS.hostLogin, { hostId, userId, sshUser, fromIp });
|
||||
} catch (err) {
|
||||
sshLogger.warn("Failed to dispatch login event", {
|
||||
operation: "login_event_dispatch_error",
|
||||
|
||||
@@ -30,18 +30,10 @@ const swaggerOptions: SwaggerJSDocOptions = {
|
||||
url: "http://localhost:30004",
|
||||
description: "SSH file manager server",
|
||||
},
|
||||
{
|
||||
url: "http://localhost:30005",
|
||||
description: "Server statistics and monitoring server",
|
||||
},
|
||||
{
|
||||
url: "http://localhost:30006",
|
||||
description: "Dashboard server",
|
||||
},
|
||||
{
|
||||
url: "http://localhost:30007",
|
||||
description: "Docker management server",
|
||||
},
|
||||
{
|
||||
url: "http://localhost:30011",
|
||||
description: "Serial connection server",
|
||||
|
||||
Reference in new issue
Block a user