Skip to content

Commit

Permalink
update queryurls
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnylqm committed Jul 27, 2024
1 parent 88bacdf commit 2357a0b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ import {
const defaultServer = {
main: 'https://update.react-native.cn/api',
backups: ['https://update.reactnative.cn/api'],
queryUrl:
queryUrls: [
'https://gitee.com/sunnylqm/react-native-pushy/raw/master/endpoints.json',
'https://cdn.jsdelivr.net/gh/reactnativecn/react-native-pushy@master/endpoints.json',
],
};

const empty = {};
Expand Down Expand Up @@ -233,9 +235,11 @@ export class Pushy {
if (!server) {
return [];
}
if (server.queryUrl) {
if (server.queryUrls) {
try {
const resp = await fetch(server.queryUrl);
const resp = await Promise.race(
server.queryUrls.map(queryUrl => fetch(queryUrl)),
);
const remoteEndpoints = await resp.json();
log('fetch endpoints:', remoteEndpoints);
if (Array.isArray(remoteEndpoints)) {
Expand All @@ -244,7 +248,7 @@ export class Pushy {
);
}
} catch (e: any) {
log('failed to fetch endpoints from: ', server.queryUrl);
log('failed to fetch endpoints from: ', server.queryUrls);
}
}
return server.backups;
Expand Down
2 changes: 1 addition & 1 deletion src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export type UpdateEventsLogger = ({
export interface PushyServerConfig {
main: string;
backups?: string[];
queryUrl?: string;
queryUrls?: string[];
}

export interface PushyOptions {
Expand Down

0 comments on commit 2357a0b

Please sign in to comment.