58 lines
1.7 KiB
TypeScript
58 lines
1.7 KiB
TypeScript
const fsPromises = require("fs/promises");
|
|
const fs = require("fs");
|
|
import axios from "axios";
|
|
import * as https from "https";
|
|
|
|
const endPointQuery = async (
|
|
url: string,
|
|
method: string,
|
|
param: string = ""
|
|
) => {
|
|
let response: any = null;
|
|
|
|
try {
|
|
const httpsAgent = new https.Agent({ rejectUnauthorized: false });
|
|
|
|
if (method == "get") {
|
|
// const url = 'https://sos.espacolaser.com.br/api/whatsapp/ticket/R32656'
|
|
response = await axios.get(url, {
|
|
httpsAgent,
|
|
headers: {
|
|
"x-access-token":
|
|
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOnsiaWQiOjEsInJvbGUiOiJjbGllbnQiLCJob3N0Ijoic29zLmVzcGFjb2xhc2VyLmNvbS5iciIsInRlbmFudCI6ImVzcGFjb2xhc2VyIiwibmFtZSI6IlNFTlNSLklUIiwiY29tcGFueSI6eyJpZCI6NDR9fSwiZGF0ZSI6MTY2MTI2MjY0MywiaWF0IjoxNjYxMjYyNjQzLCJleHAiOjE3NDc2NjI2NDN9.zf91OmRs4_C7B8OlVpLLrQMiRBYc7edP4qAdH_hqxpk",
|
|
Origin: "espacolaser"
|
|
}
|
|
});
|
|
console.log(
|
|
`TEST URL CLIENT GET ROUTE: ${url} | STATUS CODE: ${response.status}`
|
|
);
|
|
} else if (method == "post") {
|
|
// const url = 'http://177.107.193.124:8095/labs/zabbix-frontend/api/api.php'
|
|
|
|
response = await axios.post(
|
|
url,
|
|
{
|
|
auth: "0424bd59b807674191e7d77572075f33",
|
|
jsonrpc: "2.0",
|
|
method: "chamado.ematendimento",
|
|
"params[ccusto]": param,
|
|
id: "101"
|
|
},
|
|
{
|
|
httpsAgent,
|
|
headers: { "Content-Type": "multipart/form-data" }
|
|
}
|
|
);
|
|
console.log(
|
|
`TEST URL CLIENT POST ROUTE: ${url} | STATUS CODE: ${response.status}`
|
|
);
|
|
}
|
|
} catch (error) {
|
|
console.error(`Erro ao consultar endpoint ${url}: ${error}`);
|
|
}
|
|
|
|
return response;
|
|
};
|
|
|
|
export default endPointQuery;
|