diff --git a/modules/mysql/src/MySQLModule.ts b/modules/mysql/src/MySQLModule.ts index 4cb73a2d..91be3982 100644 --- a/modules/mysql/src/MySQLModule.ts +++ b/modules/mysql/src/MySQLModule.ts @@ -6,7 +6,7 @@ import { type ModuleMetadata, logger, } from "@fabernovel/heart-common" -import { MySQLClient } from "./client/Client.js" +import { MySQLClient } from "./client/MySQLClient.js" export class MySQLModule extends Module implements ModuleListenerDatabaseInterface { #client: MySQLClient diff --git a/modules/mysql/src/client/Client.ts b/modules/mysql/src/client/MySQLClient.ts similarity index 100% rename from modules/mysql/src/client/Client.ts rename to modules/mysql/src/client/MySQLClient.ts diff --git a/modules/mysql/src/client/SshClient.ts b/modules/mysql/src/client/SshClient.ts new file mode 100644 index 00000000..25484b14 --- /dev/null +++ b/modules/mysql/src/client/SshClient.ts @@ -0,0 +1,48 @@ +import { env } from "node:process" +import { Client } from "ssh2" +import databaseConfig from "../config/mikro-orm.config.js" + +export class SshClient { + #client = new Client() + #databaseUrl = new URL(databaseConfig.clientUrl ?? "") + #serverUrl = new URL(env.HEART_MYSQL_DATABASE_URL ? `ssh://${env.HEART_MYSQL_DATABASE_URL}` : "") + + constructor() { + this.#client + .on("ready", () => { + console.log("Client :: ready") + this.#client.forwardIn(this.#databaseUrl.host, Number(this.#databaseUrl.port), (err) => { + if (err) throw err + console.log("Listening for this.#clientections on server on port 8000!") + }) + }) + .on("tcp connection", (info, accept) => { + console.log("TCP :: INCOMING CONNECTION:") + console.dir(info) + accept() + .on("close", () => { + console.log("TCP :: CLOSED") + }) + .on("data", (data) => { + console.log("TCP :: DATA: " + data) + }) + .end( + [ + "HTTP/1.1 404 Not Found", + "Date: Thu, 15 Nov 2012 02:07:58 GMT", + "Server: ForwardedConnection", + "Content-Length: 0", + "Connection: close", + "", + "", + ].join("\r\n") + ) + }) + .connect({ + host: this.#serverUrl.host, + port: Number(this.#serverUrl.port), + username: this.#serverUrl.username, + password: this.#serverUrl.password, + }) + } +}