-
-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tweak(client/utils): Add and tweak various fetch utils for refactor
- Loading branch information
1 parent
ebe8c67
commit fed042a
Showing
2 changed files
with
67 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters