mirror of
https://github.com/mudabbir-ahmad/MAD-Treasure-Hunt.git
synced 2026-10-08 03:00:20 +00:00
Update API base URL comment for home network usage; simplify fetch request handling
This commit is contained in:
1 parent
a326c784a5
commit
b8efe987af
1 file changed
+3
-5
@@ -1,4 +1,5 @@
|
|||||||
export const API_BASE_URL = 'http://api.bobby.ip-ddns.com';
|
export const API_BASE_URL = 'http://api.bobby.ip-ddns.com'; //For outside Home network
|
||||||
|
//export const API_BASE_URL = 'http://192.168.8.100:3000'; //For when im home (API Endpoint is on my home server...)
|
||||||
const API = {};
|
const API = {};
|
||||||
|
|
||||||
API.get = (endpoint) => callFetch(endpoint, 'GET');
|
API.get = (endpoint) => callFetch(endpoint, 'GET');
|
||||||
@@ -21,10 +22,7 @@ const callFetch = async (endpoint, method, dataObj = null) => {
|
|||||||
// Call the fetch and process the return
|
// Call the fetch and process the return
|
||||||
try {
|
try {
|
||||||
let result = null;
|
let result = null;
|
||||||
const controller = new AbortController();
|
const response = await fetch(endpoint, requestObj);
|
||||||
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();
|
if (response.status !== 204) result = await response.json();
|
||||||
return response.status >= 200 && response.status < 300
|
return response.status >= 200 && response.status < 300
|
||||||
? {isSuccess: true, result}
|
? {isSuccess: true, result}
|
||||||
|
|||||||
Reference in new issue
Block a user