Skip to content

Commit

Permalink
omit all req options for CloudFlare Workers #96
Browse files Browse the repository at this point in the history
  • Loading branch information
adrai committed Sep 20, 2022
1 parent 8fb05d8 commit adf5ee0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
14 changes: 8 additions & 6 deletions i18nextHttpBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ var fetchIt = function fetchIt(url, fetchOptions, callback) {
}).catch(callback);
};

var omitFetchMode = false;
var omitFetchOptions = false;

var requestWithFetch = function requestWithFetch(options, url, payload, callback) {
if (options.queryStringParams) {
Expand All @@ -327,24 +327,26 @@ var requestWithFetch = function requestWithFetch(options, url, payload, callback

var headers = (0, _utils.defaults)({}, typeof options.customHeaders === 'function' ? options.customHeaders() : options.customHeaders);
if (payload) headers['Content-Type'] = 'application/json';
var reqOptions = typeof options.requestOptions === 'function' ? options.requestOptions(payload) : options.requestOptions;
var fetchOptions = (0, _utils.defaults)({
method: payload ? 'POST' : 'GET',
body: payload ? options.stringify(payload) : undefined,
headers: headers
}, typeof options.requestOptions === 'function' ? options.requestOptions(payload) : options.requestOptions);
if (omitFetchMode) delete fetchOptions.mode;
}, omitFetchOptions ? {} : reqOptions);

try {
fetchIt(url, fetchOptions, callback);
} catch (e) {
if (!fetchOptions.mode || !e.message || e.message.indexOf('mode') < 0 || e.message.indexOf('not implemented') < 0) {
if (!reqOptions || Object.keys(reqOptions).length === 0 || !e.message || e.message.indexOf('not implemented') < 0) {
return callback(e);
}

try {
delete fetchOptions.mode;
Object.keys(reqOptions).forEach(function (opt) {
delete fetchOptions[opt];
});
fetchIt(url, fetchOptions, callback);
omitFetchMode = true;
omitFetchOptions = true;
} catch (err) {
callback(err);
}
Expand Down
2 changes: 1 addition & 1 deletion i18nextHttpBackend.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit adf5ee0

Please sign in to comment.