Skip to content

Commit

Permalink
feat: first and non-functional implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Bastien Gatellier committed Aug 29, 2023
1 parent 84ddfdd commit 9c60419
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion modules/mysql/src/MySQLModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
File renamed without changes.
48 changes: 48 additions & 0 deletions modules/mysql/src/client/SshClient.ts
Original file line number Diff line number Diff line change
@@ -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,
})
}
}

0 comments on commit 9c60419

Please sign in to comment.