Hopefully fixed domain

This commit is contained in:
2025-10-13 22:33:19 +02:00
parent 1ea8938af2
commit d48daf7454
3 changed files with 17 additions and 6 deletions
+15 -4
View File
@@ -2,19 +2,30 @@ 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 ? 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;
// 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,
address: string,
wsRef: RefObject<WebSocket | null>,
setServer: Dispatch<SetStateAction<Server | undefined>>,
setMessages: Dispatch<SetStateAction<Message[]>>,
onNewMessage?: (m: Message) => void
) {
const ip = makeAddress(address);
console.log("Authenticating with server at:", ip);
const server_auth = (
(await axios.post("/api/auth", { server_ip: ip })).data as any