Skip to content

Commit

Permalink
Merge branch 'master' of github.com:athombv/node-homey-oauth2app
Browse files Browse the repository at this point in the history
  • Loading branch information
WeeJeWel committed Nov 6, 2024
2 parents 11c7acf + 51bd953 commit 2b1f4c5
Show file tree
Hide file tree
Showing 5 changed files with 624 additions and 1,459 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
"env": {
"jest/globals": true
},
"globals": {
"fetch": false
},
"plugins": ["jest"]
}
9 changes: 7 additions & 2 deletions lib/OAuth2Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { URLSearchParams } = require('url');
const { EventEmitter } = require('events');
const querystring = require('querystring');

const fetch = require('node-fetch');
const fetch = require('./OAuth2Fetch');

const OAuth2Error = require('./OAuth2Error');
const OAuth2Token = require('./OAuth2Token');
Expand Down Expand Up @@ -474,7 +474,12 @@ class OAuth2Client extends EventEmitter {
opts.body = body;
}

const url = `${this._apiUrl}${path}${urlAppend}`;
let url;
if (path.startsWith('http://') || path.startsWith('https://')) {
url = `${path}${urlAppend}`; // Allow the use of absolute URLs to ignore this._apiUrl
} else {
url = `${this._apiUrl}${path}${urlAppend}`;
}

return {
url,
Expand Down
5 changes: 5 additions & 0 deletions lib/OAuth2Fetch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

module.exports = Number(process.versions.node.split('.')[0]) >= 18
? fetch // Use native fetch on Node 18 and above
: require('node-fetch');
Loading

0 comments on commit 2b1f4c5

Please sign in to comment.