mirror of
https://github.com/zhigang1992/react-native-code-push.git
synced 2026-06-10 15:49:36 +08:00
31 lines
661 B
JavaScript
31 lines
661 B
JavaScript
module.exports = {
|
|
async request(verb, url, body, callback) {
|
|
if (typeof body === "function") {
|
|
callback = body;
|
|
body = null;
|
|
}
|
|
|
|
var headers = {
|
|
"Accept": "application/json",
|
|
"Content-Type": "application/json"
|
|
};
|
|
|
|
if (body && typeof body === "object") {
|
|
body = JSON.stringify(body);
|
|
}
|
|
|
|
try {
|
|
const response = await fetch(url, {
|
|
method: verb,
|
|
headers: headers,
|
|
body: body
|
|
});
|
|
|
|
const statusCode = response.status;
|
|
const body = await response.text();
|
|
callback(null, { statusCode, body });
|
|
} catch (err) {
|
|
callback(err);
|
|
}
|
|
}
|
|
}; |