mirror of
https://github.com/mudabbir-ahmad/MAD-Treasure-Hunt.git
synced 2026-10-07 19:00:20 +00:00
Update API base URL for local development; implement fetch timeout handling for improved request management
This commit is contained in:
1 parent
5942f8954c
commit
51ed0bc8b6
1 file changed
+5
-2
@@ -2,7 +2,7 @@ import Constants from 'expo-constants';
|
||||
|
||||
const getBaseUrl = () => {
|
||||
const host = Constants.expoGoConfig?.debuggerHost;
|
||||
if (host) return `http://${host.split(':')[0]}:3000`;
|
||||
if (host) return 'http://192.168.8.100:3000';
|
||||
return 'http://api.bobby.ip-ddns.com';
|
||||
};
|
||||
|
||||
@@ -29,7 +29,10 @@ const callFetch = async (endpoint, method, dataObj = null) => {
|
||||
// Call the fetch and process the return
|
||||
try {
|
||||
let result = null;
|
||||
const response = await fetch(endpoint, requestObj);
|
||||
const controller = new AbortController();
|
||||
const timeoutId = setTimeout(() => controller.abort(), 10000);
|
||||
const response = await fetch(endpoint, {...requestObj, signal: controller.signal});
|
||||
clearTimeout(timeoutId);
|
||||
if (response.status !== 204) result = await response.json();
|
||||
return response.status >= 200 && response.status < 300
|
||||
? {isSuccess: true, result}
|
||||
|
||||
Reference in new issue
Block a user