Skip to content
Browse files

Added support for API hosts with non-standard ports. Previously an AP…

…I host of "localhost:8080" would actually set "localhost:8080" as the 'host' option to the AJAX request. This would fail horribly. Now the port is split out and passed as the 'port' option to the request. If no ":<port>" is provided, Node will use the protocol default, if any.
  • Loading branch information...
1 parent 6db92c9 commit 5e9f9d45c7900fc23f3625e2b1f29974bbed68cb @adamkaplan adamkaplan committed Sep 13, 2011
Showing with 6 additions and 1 deletion.
  1. +6 −1 app.js
View
7 app.js
@@ -298,12 +298,17 @@ function processRequest(req, res, next) {
}
}
+ var baseHostInfo = apiConfig.baseURL.split(':');
+ var baseHostUrl = baseHostInfo[0],
+ baseHostPort = (baseHostInfo.length > 1) ? baseHostInfo[1] : "";
+
var paramString = query.stringify(params),
privateReqURL = apiConfig.protocol + '://' + apiConfig.baseURL + apiConfig.privatePath + methodURL + ((paramString.length > 0) ? '?' + paramString : ""),
options = {
headers: {},
protocol: apiConfig.protocol,
- host: apiConfig.baseURL,
+ host: baseHostUrl,
+ port: baseHostPort,
method: httpMethod,
path: apiConfig.publicPath + methodURL + ((paramString.length > 0) ? '?' + paramString : "")
};

0 comments on commit 5e9f9d4

Please sign in to comment.
Something went wrong with that request. Please try again.