Skip to content

Commit

Permalink
Merge pull request #138 from paul-rouse/master
Browse files Browse the repository at this point in the history
On node.js don't override a base url already set in xhr2
  • Loading branch information
garyb authored Sep 5, 2019
2 parents ec9c50e + 3249a34 commit e286329
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/Affjax.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ exports._ajax = function () {
return new XHR();
};

platformSpecific.fixupUrl = function (url) {
var urllib = module.require("url");
var u = urllib.parse(url);
u.protocol = u.protocol || "http:";
u.hostname = u.hostname || "localhost";
return urllib.format(u);
platformSpecific.fixupUrl = function (url, xhr) {
if (xhr.nodejsBaseUrl === null) {
var urllib = module.require("url");
var u = urllib.parse(url);
u.protocol = u.protocol || "http:";
u.hostname = u.hostname || "localhost";
return urllib.format(u);
} else {
return url || "/";
}
};

platformSpecific.getResponse = function (xhr) {
Expand All @@ -42,7 +46,7 @@ exports._ajax = function () {
return function (mkHeader, options) {
return function (errback, callback) {
var xhr = platformSpecific.newXHR();
var fixedUrl = platformSpecific.fixupUrl(options.url);
var fixedUrl = platformSpecific.fixupUrl(options.url, xhr);
xhr.open(options.method || "GET", fixedUrl, true, options.username, options.password);
if (options.headers) {
try {
Expand Down

0 comments on commit e286329

Please sign in to comment.