UNPKG

@platform/http

Version:
21 lines (20 loc) 1.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var isomorphicFetch = require("isomorphic-fetch"); var common_1 = require("../common"); exports.fetch = function (req) { return tslib_1.__awaiter(void 0, void 0, void 0, function () { var url, method, mode, data, toBody, headers, body; return tslib_1.__generator(this, function (_a) { url = req.url, method = req.method, mode = req.mode, data = req.data; toBody = function () { var body = common_1.util.isFormData(req.headers) ? data : common_1.util.stringify(data, function () { return "Failed to " + method + " to '" + url + "'. The data could not be serialized to JSON."; }); return body || undefined; }; headers = common_1.util.toRawHeaders(req.headers); body = ['GET', 'HEAD'].includes(method) ? undefined : toBody(); return [2, isomorphicFetch(url, { method: method, mode: mode, body: body, headers: headers })]; }); }); };