Skip to content

Commit 67307b2

Browse files
committed
fix: troubles with getting server information if the port is specified
1 parent bde13e2 commit 67307b2

3 files changed

Lines changed: 15 additions & 7 deletions

File tree

frontend/src/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const config = {
1010
username_occupied: 'Даний юзернейм уже використовується!',
1111
user_delete_success: 'Ваш акаунт видалено успішно!'
1212
},
13+
defaultServerIcon: 'https://media.minecraftforum.net/attachments/thumbnails/300/619/115/115/636977108000120237.png',
1314
}
1415
export default config;
1516
export type StatusKey = keyof typeof config.MESSAGES;

frontend/src/pages/Server/Server.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { toast } from "sonner";
1212
import moment from "moment";
1313
import { RiArrowLeftLine } from "react-icons/ri";
1414
import { useAuth } from "../../hooks/useAuth";
15+
import config from "../../config";
1516

1617
const ServerPage = () => {
1718
const {id} = useParams();
@@ -89,7 +90,7 @@ const ServerPage = () => {
8990
</div>
9091
<div className="bg-green-700 p-4 sm:w-2/5 rounded">
9192
<div className="flex w-full items-center justify-between">
92-
<img className="h-16 w-16" src={serverInfo.icon} />
93+
<img className="h-16 w-16" src={serverInfo.icon ?? config.defaultServerIcon} />
9394
<div className="text-sm sm:text-base whitespace-pre-wrap max-w-52">
9495
{serverInfo.motd ? <>
9596
<p>{parse(serverInfo.motd.html[0])}</p>
@@ -101,8 +102,8 @@ const ServerPage = () => {
101102
<div className="bg-gray-400 rounded p-1">
102103
<p>IP адреса:</p>
103104
<div className="flex items-center">
104-
<p>{server.formatted_address}</p>
105-
<CopyBtn text={server.formatted_address} />
105+
<p>{serverInfo.debug.srv ? server.address : server.formatted_address}</p>
106+
<CopyBtn text={serverInfo.debug.srv ? server.address : server.formatted_address} />
106107
</div>
107108
</div>
108109
<div className="grid grid-cols-2">

frontend/src/util/getServerStatusInfo.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,24 @@ interface ServerStatusInfoType {
1616
software: string;
1717
debug: {
1818
cachetime: number;
19+
srv: boolean;
1920
};
2021
address: string;
2122
port: number;
2223
}
2324

2425
const getServerStatusInfo = async (address: string, port?: number): Promise<void | ServerStatusInfoType> => {
25-
return await apiClient.get<ServerStatusInfoType>(port ? `/${address}:${port}` : `/${address}`, {
26+
let info = await apiClient.get<ServerStatusInfoType>(port ? `/${address}:${port}` : `/${address}`, {
2627
baseURL: 'https://api.mcsrvstat.us/3/',
2728
withCredentials: false,
28-
})
29-
.then(resp => resp.data)
30-
.catch(err => console.log(err));
29+
});
30+
if (port && info.data.port != port) {
31+
info = await apiClient.get<ServerStatusInfoType>(`/${address}`, {
32+
baseURL: 'https://api.mcsrvstat.us/3/',
33+
withCredentials: false,
34+
});
35+
};
36+
return info.data;
3137
}
3238

3339
export default getServerStatusInfo;

0 commit comments

Comments
 (0)