mirror of
https://github.com/qbcore-fivem/qb-core.git
synced 2026-09-04 16:23:21 +00:00
feat (html): Organised html file - Darknight2590
* Rename html/app.js to html/js/app.js * Rename html/config.js to html/js/config.js * Rename html/drawtext.js to html/js/drawtext.js * Rename html/testing.js to html/js/testing.js * Rename html/utils.js to html/js/utils.js * Rename html/style.css to html/css/style.css * Rename html/drawtext.css to html/css/drawtext.css * Update fxmanifest.lua
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
// Returns whether we are in browser or not
|
||||
export const isEnvBrowser = () => !window.invokeNative;
|
||||
|
||||
/**
|
||||
* Real simple wrapper around fetch api for NUI focus
|
||||
* it will return the mockData param if we are in browser. So we don't
|
||||
* make a useless request to a hostname that doesn't exist.
|
||||
* @param evName {string} - The callback event name/type
|
||||
* @param data {any} - Optional `body` data JSON stringified & passed with the request
|
||||
* @param mockData {any} - Mock data to return if this is running in browser
|
||||
* @return Promise
|
||||
**/
|
||||
export const fetchNui = async (evName, data, mockData = null) => {
|
||||
if (isEnvBrowser()) return mockData;
|
||||
|
||||
const resourceName = window.GetParentResourceName();
|
||||
|
||||
const rawResp = await fetch(`https://${resourceName}/${evName}`, {
|
||||
body: JSON.stringify(data),
|
||||
headers: {
|
||||
"Content-Type": "application/json; charset=UTF8",
|
||||
},
|
||||
method: "POST",
|
||||
});
|
||||
|
||||
return await rawResp.json();
|
||||
};
|
||||
Reference in New Issue
Block a user