Skip to content

Commit

Permalink
サーバー情報の取得前でも、URLの一覧を返す (fix #2)
Browse files Browse the repository at this point in the history
  • Loading branch information
m-hayabusa committed Sep 8, 2024
1 parent 710d536 commit 8953944
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion backend/src/GenerateServerList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import htmlParser from "node-html-parser";
export let result: ApiResponse.Server[] = [];

const init = async () => {
result = await listup(true);
result = await listup();
setInterval(
async () => {
Expand All @@ -17,14 +18,20 @@ const init = async () => {
};
init();

async function listup(): Promise<ApiResponse.Server[]> {
async function listup(quick?: boolean): Promise<ApiResponse.Server[]> {
const client = createClient();
await client.connect();
const keys = await client.keys("relay:subscription:*");
const hosts = keys
.map(key => key.substring(19))
.filter(host => host !== "localhost");

if (quick) {
return hosts.map(
host => new ApiResponse.Server({ url: `https://${host}` })
);
}

return Promise.all(hosts.map(getNodeInfo));
}

Expand Down

0 comments on commit 8953944

Please sign in to comment.