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(() => { useEffect(() => {
if (!ip) return; if (!ip) return;
auth(makeAddress(ip, 7080), wsServerRef, setServer, setMessages); auth(ip, wsServerRef, setServer, setMessages);
}, [ip]); }, [ip]);
return ( return (
+1 -1
View File
@@ -69,7 +69,7 @@ export default function AppSidebar({
if (!user?.node_address) return; if (!user?.node_address) return;
if (setUser) setUser(user); if (setUser) setUser(user);
auth( auth(
makeAddress(user?.node_address, 7090), user?.node_address,
wsRef, wsRef,
() => {}, () => {},
setMessages, setMessages,
+15 -4
View File
@@ -2,10 +2,20 @@ import { Message, Server } from "@/types/types";
import axios from "axios"; import axios from "axios";
import { Dispatch, RefObject, SetStateAction } from "react"; import { Dispatch, RefObject, SetStateAction } from "react";
export function makeAddress(ip: string, defaultPort = 7080) { async function getIP(domain: string) {
// return ip.includes(":") ? `${ip}` : `${ip}:${defaultPort}`; 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) // Apparently wss doesn't like ports (or maybe the tunnel I'm using)
return ip; // return ip.includes(":") ? `${ip}` : `${ip}:${defaultPort}`;
if (ip.match(/^\d\.\d\.\d\.\d/)) {
return ip;
}
return await getIP(ip);
} }
export default async function auth( export default async function auth(
@@ -17,7 +27,8 @@ export default async function auth(
) { ) {
console.log("Authenticating with server at:", ip); console.log("Authenticating with server at:", ip);
const server_auth = ( 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; ).token;
// Open the WebSocket connection // Open the WebSocket connection