Skip to content

Commit a79bcca

Browse files
author
dfounderliu
committed
add proxy
1 parent 3f201fa commit a79bcca

File tree

2 files changed

+35
-18
lines changed

2 files changed

+35
-18
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "tencent-cloud-sdk",
33
"description": "Tencent Cloud SDK For Serverless Framework",
4-
"version": "0.0.4",
4+
"version": "0.0.5",
55
"main": "./index.js",
66
"publishConfig": {
77
"access": "public"

src/client.js

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const assign = require('object-assign')
22
const qs = require('querystring')
33
const dotQs = require('dot-qs')
4-
const https = require('https')
4+
const request = require('../lib/request/index')
55
const crypto = require('crypto')
66
const cos = require('../lib/cos/cos')
77

@@ -65,22 +65,39 @@ class TencentCloudClient {
6565

6666
async doCloudApiRequest(data) {
6767
const httpBody = await this.cloudApiGenerateQueryString(data)
68-
const options = {
69-
hostname: this.service.host,
70-
path: this.service.path + '?' + httpBody
71-
}
72-
return new Promise(function(resolve, reject) {
73-
const req = https.get(options, function(res) {
74-
res.setEncoding('utf8')
75-
res.on('data', function(chunk) {
76-
resolve(JSON.parse(chunk))
77-
})
78-
})
79-
req.on('error', function(e) {
80-
reject(e.message)
81-
})
82-
// req.write(httpBody)
83-
req.end()
68+
69+
// const options = {
70+
// hostname: this.service.host,
71+
// path: this.service.path + '?' + httpBody
72+
// }
73+
// return new Promise(function(resolve, reject) {
74+
// const req = https.get(options, function(res) {
75+
// res.setEncoding('utf8')
76+
// res.on('data', function(chunk) {
77+
// resolve(JSON.parse(chunk))
78+
// })
79+
// })
80+
// req.on('error', function(e) {
81+
// reject(e.message)
82+
// })
83+
// // req.write(httpBody)
84+
// req.end()
85+
// })
86+
87+
const url = `https://${this.service.host}${this.service.path}?${httpBody}`
88+
return new Promise(function(resolve, rejecte) {
89+
request(
90+
{
91+
url: url,
92+
method: 'GET'
93+
},
94+
function(error, response, body) {
95+
if (!error && response.statusCode == 200) {
96+
resolve(JSON.parse(body))
97+
}
98+
rejecte(error)
99+
}
100+
)
84101
})
85102
}
86103
}

0 commit comments

Comments
 (0)