1 Star 0 Fork 1

碳猫科技/react-native-code-push

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
request-fetch-adapter.js 1.26 KB
一键复制 编辑 原始数据 按行查看 历史
const packageJson = require("./package.json");
module.exports = {
async request(verb, url, requestBody, callback) {
if (typeof requestBody === "function") {
callback = requestBody;
requestBody = null;
}
const headers = {
"Accept": "application/json",
"Content-Type": "application/json",
"X-CodePush-Plugin-Name": packageJson.name,
"X-CodePush-Plugin-Version": packageJson.version,
"X-CodePush-SDK-Version": packageJson.dependencies["code-push"]
};
if (requestBody && typeof requestBody === "object") {
requestBody = JSON.stringify(requestBody);
}
try {
const response = await fetch(url, {
method: getHttpMethodName(verb),
headers: headers,
body: requestBody
});
const statusCode = response.status;
const body = await response.text();
callback(null, { statusCode, body });
} catch (err) {
callback(err);
}
}
};
function getHttpMethodName(verb) {
// Note: This should stay in sync with the enum definition in
// https://github.com/Microsoft/code-push/blob/master/sdk/script/acquisition-sdk.ts#L6
return [
"GET",
"HEAD",
"POST",
"PUT",
"DELETE",
"TRACE",
"OPTIONS",
"CONNECT",
"PATCH"
][verb];
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Objective-C
1
https://gitee.com/hackcat/react-native-code-push.git
git@gitee.com:hackcat/react-native-code-push.git
hackcat
react-native-code-push
react-native-code-push
master

搜索帮助