Closed triestpa closed 6 years ago
Hello, First off, thanks for the great library.
At the moment, the default URL query string is not compatible with all MediaWiki APIs. The origin=* parameter causes issues on some MediaWikis. For instance - Running
origin=*
wiki({ apiUrl: 'http://awoiaf.westeros.org/api.php' }).search('Winterfell').then(console.log)
results in this URL request -
https://awoiaf.westeros.org/api.php?list=search&srsearch=Winterfell&srlimit=50&format=json&action=query&origin=*&redirects=
Which returns an error - 'origin' parameter does not match Origin header.
'origin' parameter does not match Origin header
Removing the origin=* parameter results in a correct API response -
https://awoiaf.westeros.org/api.php?list=search&srsearch=Winterfell&srlimit=50&format=json&action=query&redirects=
{ "query": { "searchinfo": { "totalhits": 28 }, "search": [ { "ns": 0, "title": "Winterfell", "snippet": "| name\t\t= <span class='searchmatch'>Winterfell</span>\n| image\t\t= [[File:Ted Nasmith A Song of Ice and Fire <span class='searchmatch'>Winterfell</span>.jpg|350px]]\n", "size": 28785, "wordcount": 4547, "timestamp": "2017-04-11T20:21:56Z" }, { "ns": 0, "title": "Crypts beneath Winterfell", "snippet": "#REDIRECT [[crypt of <span class='searchmatch'>Winterfell</span>]]\n", "size": 55, "wordcount": 6, "timestamp": "2016-06-21T17:50:29Z" }, ... ] } }
It seems that a reasonably simple solution to this would be allowing a configuration option to in the wiki() object constructor, such as -
wiki()
wiki({ apiUrl: 'http://awoiaf.westeros.org/api.php', setOriginParam: false })
What do you think?
Thanks for the great issue description and potential solution!
Let me give this a try.
Fixed in v4.1.0
Also added to documentation.
Great, thanks for the fix!
Hello, First off, thanks for the great library.
The Issue -
At the moment, the default URL query string is not compatible with all MediaWiki APIs. The
origin=*
parameter causes issues on some MediaWikis. For instance - Runningresults in this URL request -
Which returns an error -
'origin' parameter does not match Origin header
.Solution
Removing the
origin=*
parameter results in a correct API response -Proposed Change
It seems that a reasonably simple solution to this would be allowing a configuration option to in the
wiki()
object constructor, such as -What do you think?