Skip to content

Commit 2cf7336

Browse files
committed
add fallback for android <= 7.0
1 parent 7eac48a commit 2cf7336

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-update",
3-
"version": "10.28.11",
3+
"version": "10.29.0",
44
"description": "react-native hot update",
55
"main": "src/index",
66
"scripts": {

src/client.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
assertDev,
44
assertWeb,
55
emptyObj,
6+
enhancedFetch,
67
joinUrls,
78
log,
89
noop,
@@ -261,7 +262,7 @@ export class Pushy {
261262
type: 'checking',
262263
message: this.options.appKey + ': ' + stringifyBody,
263264
});
264-
resp = await fetch(this.getCheckUrl(), fetchPayload);
265+
resp = await enhancedFetch(this.getCheckUrl(), fetchPayload);
265266
} catch (e: any) {
266267
this.report({
267268
type: 'errorChecking',
@@ -272,7 +273,7 @@ export class Pushy {
272273
try {
273274
resp = await promiseAny(
274275
backupEndpoints.map(endpoint =>
275-
fetch(this.getCheckUrl(endpoint), fetchPayload),
276+
enhancedFetch(this.getCheckUrl(endpoint), fetchPayload),
276277
),
277278
);
278279
} catch (err: any) {

src/utils.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ const ping =
4040
: async (url: string) => {
4141
let pingFinished = false;
4242
return Promise.race([
43-
fetch(url, {
43+
enhancedFetch(url, {
4444
method: 'HEAD',
4545
})
46-
.then(({ status, statusText }) => {
46+
.then(({ status, statusText, url: finalUrl }) => {
4747
pingFinished = true;
4848
if (status === 200) {
49-
return url;
49+
return finalUrl;
5050
}
5151
log('ping failed', url, status, statusText);
5252
throw new Error('Ping failed');
@@ -69,7 +69,7 @@ const ping =
6969

7070
export function joinUrls(paths: string[], fileName?: string) {
7171
if (fileName) {
72-
return paths.map(path => 'https://' + path + '/' + fileName);
72+
return paths.map(path => `https://${path}/${fileName}`);
7373
}
7474
}
7575

@@ -108,3 +108,23 @@ export const assertDev = (matter: string) => {
108108
}
109109
return true;
110110
};
111+
112+
export const isAndroid70AndBelow = () => {
113+
// android 7.0 and below devices do not support letsencrypt cert
114+
// https://letsencrypt.org/2023/07/10/cross-sign-expiration/
115+
return Platform.OS === 'android' && Platform.Version <= 24;
116+
};
117+
118+
export const enhancedFetch = async (
119+
url: string,
120+
params: Parameters<typeof fetch>[1],
121+
) => {
122+
return fetch(url, params).catch(e => {
123+
log('fetch error', url, e);
124+
if (isAndroid70AndBelow()) {
125+
log(`try fallback to http because android version: ${Platform.Version}`);
126+
return fetch(url.replace('https', 'http'), params);
127+
}
128+
throw e;
129+
});
130+
};

0 commit comments

Comments
 (0)