ed
This commit is contained in:
parent
510e3ffcf2
commit
f43cf424cf
305 changed files with 34683 additions and 0 deletions
26
resources/[carscripts]/community_bridge/web/src/fetch.jsx
Normal file
26
resources/[carscripts]/community_bridge/web/src/fetch.jsx
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
export const fetchNui = async (cbName, data = {}) => {
|
||||
const options = {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
body: JSON.stringify(data)
|
||||
};
|
||||
|
||||
try {
|
||||
const resourceName = window.GetParentResourceName?.() || '';
|
||||
const resp = await fetch(`https://${resourceName}/${cbName}`, options);
|
||||
|
||||
if (!resp.ok) {
|
||||
throw new Error(`HTTP error! status: ${resp.status}`);
|
||||
}
|
||||
|
||||
return await resp.json();
|
||||
} catch (error) {
|
||||
console.error(`Fetch error for ${cbName}:`, error);
|
||||
if (!window.GetParentResourceName?.()) {
|
||||
console.error('Resource name is null - are you testing in browser?');
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue