Skip to content

Commit

Permalink
Added router hostname to env and replaced ssh2 with node-ssh
Browse files Browse the repository at this point in the history
  • Loading branch information
micthiesen committed Oct 18, 2024
1 parent cc721d7 commit 34189df
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 31 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ PUSHOVER_USER=
PUSHOVER_TOKEN=
SSH_USERNAME=
SSH_PASSWORD=
ROUTER_HOSTNAME=
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
"dependencies": {
"@hono/node-server": "^1.13.2",
"hono": "^4.6.5",
"ssh2": "^1.16.0",
"node-ssh": "^13.2.0",
"zod": "^3.23.8"
},
"devDependencies": {
"@types/ssh2": "^1.15.1",
"@biomejs/biome": "1.9.3",
"@types/node": "^20.11.17",
"@dotenvx/dotenvx": "^1.2.0",
Expand Down
74 changes: 49 additions & 25 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 12 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
import { type HttpBindings, serve } from "@hono/node-server";
import { Hono } from "hono";
import ssh from "ssh2";
import { NodeSSH } from "node-ssh";
import { z } from "zod";

ssh.createAgent(socketPath);

const env = z
.object({
PUSHOVER_USER: z.string(),
PUSHOVER_TOKEN: z.string(),
SSH_USERNAME: z.string(),
SSH_PASSWORD: z.string(),
ROUTER_HOSTNAME: z.string().ip({ version: "v4" }),
})
.parse(process.env);

const app = new Hono<{ Bindings: HttpBindings }>();

app.get("/toggle-dns", (c) => {
app.get("/toggle-dns", async (c) => {
const ssh = new NodeSSH();
await ssh.connect({
hostname: env.ROUTER_HOSTNAME,
username: env.SSH_USERNAME,
password: env.SSH_PASSWORD,
});

const resp = c.text("Hono meets Node.js");
console.log(`${c.env.incoming.method} ${c.env.incoming.url}`);
return resp;
Expand Down

0 comments on commit 34189df

Please sign in to comment.