Skip to content

Commit 1329248

Browse files
committed
chore: hostnetwork , remove http
1 parent 7a2a3b3 commit 1329248

File tree

1 file changed

+21
-39
lines changed

1 file changed

+21
-39
lines changed

src/index.ts

+21-39
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import http from "http";
21
import WebSocket from "ws";
32
import { CoreV1Api, KubeConfig } from "@kubernetes/client-node";
43
import { execSync } from "child_process";
54
import vdf from "vdf-parser";
65
import fs from "fs";
7-
import dns from "dns";
6+
import os from "os";
87

98
const kc = new KubeConfig();
109
kc.loadFromDefault();
@@ -139,27 +138,28 @@ async function getNode() {
139138
}
140139

141140
async function getLanIP() {
142-
try {
143-
const node = await getNode();
141+
const interfaces = os.networkInterfaces();
142+
for (const name of Object.keys(interfaces)) {
143+
const ips = interfaces[name];
144144

145-
const hostname = node.status?.addresses?.find(
146-
(addr) => addr.type === "Hostname",
147-
)?.address;
148-
if (hostname) {
149-
return await new Promise((resolve, reject) => {
150-
dns.lookup(hostname, (err, address) => {
151-
if (err) {
152-
reject(err);
153-
}
154-
155-
console.info(`lan ip: ${address}`);
156-
157-
resolve(address);
158-
});
159-
});
145+
if (!ips) {
146+
continue;
147+
}
148+
149+
for (const { family, address, internal } of ips) {
150+
if (
151+
internal ||
152+
family !== "IPv4" ||
153+
name.startsWith("tailscale") ||
154+
name.startsWith("cni")
155+
) {
156+
continue;
157+
}
158+
159+
console.info(`lan ip: ${address}`);
160+
161+
return address;
160162
}
161-
} catch (error) {
162-
console.warn(`unable to get lan ip`, error);
163163
}
164164
}
165165

@@ -186,24 +186,6 @@ process.once("SIGUSR2", () => {
186186

187187
setupWebSocket();
188188

189-
const hostname = "0.0.0.0";
190-
const port = 80;
191-
192-
const server = http.createServer((req, res) => {
193-
if (req.url === "/ping") {
194-
console.info("GOT PING");
195-
res.statusCode = 200;
196-
res.end();
197-
} else {
198-
res.statusCode = 404;
199-
res.end("Not Found");
200-
}
201-
});
202-
203-
server.listen(port, hostname, () => {
204-
console.log(`ping endpoint is ready.`);
205-
});
206-
207189
async function getCsVersion() {
208190
if (!fs.existsSync("/serverfiles/steamapps/appmanifest_730.acf")) {
209191
return;

0 commit comments

Comments
 (0)