Skip to content

Commit

Permalink
fix: node-fetch doesn't support the qs option (Kong#213)
Browse files Browse the repository at this point in the history
  • Loading branch information
erunion authored Apr 20, 2021
1 parent bbf75ee commit d82a992
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 9 deletions.
6 changes: 1 addition & 5 deletions src/targets/node/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,11 @@ module.exports = function (source, options) {
var code = new CodeBuilder(opts.indent)

code.push('const fetch = require(\'node-fetch\');')
var url = source.url
var url = source.fullUrl
var reqOpts = {
method: source.method
}

if (Object.keys(source.queryObj).length) {
reqOpts.qs = source.queryObj
}

if (Object.keys(source.headersObj).length) {
reqOpts.headers = source.headersObj
}
Expand Down
3 changes: 1 addition & 2 deletions test/fixtures/output/node/fetch/full.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ const encodedParams = new URLSearchParams();

encodedParams.set('foo', 'bar');

let url = 'http://mockbin.com/har';
let url = 'http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value';

let options = {
method: 'POST',
qs: {foo: ['bar', 'baz'], baz: 'abc', key: 'value'},
headers: {
accept: 'application/json',
'content-type': 'application/x-www-form-urlencoded',
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/output/node/fetch/query.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const fetch = require('node-fetch');

let url = 'http://mockbin.com/har';
let url = 'http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value';

let options = {method: 'GET', qs: {foo: ['bar', 'baz'], baz: 'abc', key: 'value'}};
let options = {method: 'GET'};

fetch(url, options)
.then(res => res.json())
Expand Down

0 comments on commit d82a992

Please sign in to comment.