AidanWelch / google-translate-api

An updated free and unlimited API for Google Translate :dollar: :no_entry_sign:
MIT License
143 stars 21 forks source link

Enable user supplied req options #36

Closed chasen-bettinger closed 1 year ago

chasen-bettinger commented 1 year ago

Hello! Thank you for the great library. I was attempting to use this in Cloudfare workers and it appears that for some unknown reason, they disallow the use of the credentials field in HTTP requests. This change enables the user to have more control over what request options are being used so that in the case of Cloudfare workers, the credentials field can be omitted.

AidanWelch commented 1 year ago

Hi, thanks for taking the time to look at the code and make a PR, but I think this is good use case where people could write small custom requestFunctions, for your example:

function requestFunction (url, fetchinit) {
    const opt = { ...fetchinit };
    delete opt.credentials;
    fetch(url, opt);
}
const res = await translate('cat', {from: 'en', to: 'es', forceBatch: false, requestFunction});
AidanWelch commented 1 year ago

Closing as inactive, feel free to comment if anyone wants it re-opened