UI_MFA/src/utils/api.ts

37 lines
1.0 KiB
TypeScript

export const fetchData = async(endpoints="", requestType="GET", requestBody:Record<string,any>|null =null)=>{
try{
const options:RequestInit={
method:requestType,
headers:{
"Content-Type":"application/json",
"Authorization": "ApiKey NS00TXlKUUIweUhWaGFuUUpUVTk6bWNVWXI1VXRSN2VWcFRtaEZ6NmdCUQ=="
},
mode: "cors"
}
if (requestType !=="GET" && requestBody){
console.log("before JSON.stringify")
options.body = JSON.stringify(requestBody)
}
console.log("callign endpoints: ", endpoints)
// const response = await fetch(`${endpoints}`, options)
const response = await fetch("https://192.168.99.121/search", options)
if (!response.ok){
throw new Error(`HTTP error! Status: ${response.status}`)
}
return await response.json()
}
catch(error){
console.log("Fetch error:", error)
return null
}
}