UNPKG

gb_utils

Version:
47 lines (42 loc) 1.06 kB
// Import Modules const axios = require("axios"); const utils = {}; // Post APi utils.postApi = async (url, req) => { try { const response = await axios.post(url, req.body, { headers: { "Content-Type": "application/json", Authorization: req.headers.authorization, "user-agent": req.headers["user-agent"], deviceid: req.headers.deviceid, ip: req.headers.ip, devicetype: req.headers.devicetype, platform: req.headers.platform, }, }); return response.data; } catch (error) { return error.response.data; } }; // Get APi utils.getApi = async (url, req) => { try { const response = await axios.get(url, req.body, { headers: { "Content-Type": "application/json", Authorization: req.headers.authorization, "user-agent": req.headers["user-agent"], deviceid: req.headers.deviceid, ip: req.headers.ip, devicetype: req.headers.devicetype, platform: req.headers.platform, }, }); return response.data; } catch (error) { return error.response.data; } }; module.exports = utils;