Merge pull request #10 from kleo-dev/testing-domain

Hopefully fixed domain
This commit is contained in:
Klesti Selimaj
2025-10-13 22:52:04 +02:00
committed by GitHub
3 changed files with 17 additions and 6 deletions
+1 -1
View File
@@ -19,7 +19,7 @@ export default function Server() {
useEffect(() => {
if (!ip) return;
auth(makeAddress(ip, 7080), wsServerRef, setServer, setMessages);
auth(ip, wsServerRef, setServer, setMessages);
}, [ip]);
return (
+1 -1
View File
@@ -69,7 +69,7 @@ export default function AppSidebar({
if (!user?.node_address) return;
if (setUser) setUser(user);
auth(
makeAddress(user?.node_address, 7090),
user?.node_address,
wsRef,
() => {},
setMessages,
+14 -3
View File
@@ -2,12 +2,22 @@ import { Message, Server } from "@/types/types";
import axios from "axios";
import { Dispatch, RefObject, SetStateAction } from "react";
export function makeAddress(ip: string, defaultPort = 7080) {
// return ip.includes(":") ? `${ip}` : `${ip}:${defaultPort}`;
async function getIP(domain: string) {
const res = await fetch(`https://dns.google/resolve?name=${domain}&type=A`);
const data = await res.json();
return data.Answer[0]?.data || null;
}
export async function makeAddress(ip: string, defaultPort = 7080) {
// Apparently wss doesn't like ports (or maybe the tunnel I'm using)
// return ip.includes(":") ? `${ip}` : `${ip}:${defaultPort}`;
if (ip.match(/^\d\.\d\.\d\.\d/)) {
return ip;
}
return await getIP(ip);
}
export default async function auth(
ip: string,
wsRef: RefObject<WebSocket | null>,
@@ -17,7 +27,8 @@ export default async function auth(
) {
console.log("Authenticating with server at:", ip);
const server_auth = (
(await axios.post("/api/auth", { server_ip: ip })).data as any
(await axios.post("/api/auth", { server_ip: await makeAddress(ip) }))
.data as any
).token;
// Open the WebSocket connection