| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- const axios = require('axios')
- const https = require('https')
- const coba = require('./coba')
- const { PRODUCTION } = require('./constanta')
- /**
- *
- * @param url {string}
- * @param token {string | null?}
- * @returns {Promise<any>}
- */
- exports.get = async (url, token = null) => {
- let response
- if (coba.decrypt(process.env.CXQSB) === PRODUCTION && token) {
- response = await axios.get(url, {
- headers: {
- Authorization: `Bearer ${token}`,
- Accept: 'application/json'
- }
- })
- } else {
- let token = process.env.XNX1Q
- response = await axios.get(url, {
- headers: {
- Authorization: `Bearer ${coba.decrypt(token)}`,
- Accept: 'application/json'
- },
- httpsAgent: new https.Agent({
- rejectUnauthorized: false
- })
- })
- }
- return response.data
- }
- /**
- *
- * @param url
- * @param data
- * @param token {string | null?}
- * @param config {any?}
- * @returns {Promise<any>}
- */
- exports.post = async (url, data, token= null, config = {}) => {
- let response
- const agent = new https.Agent({
- rejectUnauthorized: false,
- })
- if (coba.decrypt(process.env.CXQSB) === PRODUCTION && token) {
- response = await axios.post(url, data,{
- headers: {
- Authorization: `Bearer ${token}`,
- Accept: 'application/json',
- ...config
- },
- httpsAgent: agent
- })
- } else {
- let token = process.env.XNX1Q
- response = await axios.post(url, data, {
- headers: {
- Authorization: `Bearer ${coba.decrypt(token)}`,
- Accept: 'application/json',
- ...config
- },
- httpsAgent: new https.Agent({
- rejectUnauthorized: false
- })
- })
- }
- return response.data
- }
|