小程序在云函数勾选本地调试模式正常,但关闭云函数本地调试后返回401?
API/组件名称: 云函数 微信版本号:3.2.1.132 基础库版本号:2.11.0[407] 云函数代码如下: const cloud = require('wx-server-sdk')
var rp = require('request-promise')
cloud.init({
env: cloud.DYNAMIC_CURRENT_ENV
})
// 云函数入口函数
exports.main = async (event, context) => {
let url = 'https://api.vultr.com/v2/instances'
let tokenheader = "Bearer *************";
return await rp({
url: url,
headers: {
'Authorization': tokenheader,
}
}).then(function (res) {
return res
}).catch(function (err) {
return err
});
期望结果:云函数正常返回200 实际结果:在云开发-云函数-云函数本地调试下,函数正常返回,关闭云函数本地调试报错: [图片] 查看调试控制台network,发现异常时: [图片] Response: {
"errCode": -404011,
"errMsg": "Error: errCode: -404011 cloud function execution error | errMsg: cloud.callFunction:fail requestID ed479fd2-b627-11eb-a01d-5254002d4a45, cloud function service error code -504002, error message HTTPError: Response code 401 (Unauthorized)\n at EventEmitter.emitter.on (/var/user/node_modules/got/source/as-promise.js:74:19)\n at process._tickCallback (internal/process/next_tick.js:68:7); at cloud.callFunction api; "
}
请求像是没有经过云函数转发到我的服务器后端。