mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 14:38:45 +00:00
tweak(client/utils): Add and tweak various fetch utils for refactor
This commit is contained in:
1 parent
ebe8c67369
commit
fed042aea7
2 files changed
+67
-6
No files matched your search
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Simple wrapper around fetch API tailored for CEF/NUI use.
|
||||
* @param eventName - The endpoint eventname to target
|
||||
* @param data - Data you wish to send in the NUI Callback
|
||||
*
|
||||
* @return returnData - A promise for the data sent back by the NuiCallbacks CB argument
|
||||
*/
|
||||
import LogDebugEvent from '../os/debug/LogDebugEvents';
|
||||
|
||||
export async function fetchNui<T = any>(eventName: string, data?: any): Promise<T> {
|
||||
const options = {
|
||||
method: 'post',
|
||||
headers: {
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
};
|
||||
|
||||
LogDebugEvent({ data, action: 'fetchNui' });
|
||||
|
||||
const resourceName = (window as any)?.GetParentResourceName() || 'npwd';
|
||||
|
||||
const resp = await fetch(`https://${resourceName}/${eventName}`, options);
|
||||
|
||||
return await resp.json();
|
||||
}
|
||||
Reference in new issue
Block a user