Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Support for non-standard ports and cleaner unsecure auth #7

Merged
merged 3 commits into from

2 participants

@adamkaplan

The main change here is support for port in the API host spec. e.g. "baseURL": "localhost:8087", but I also cleaned up the garbage in the URL when no GET params or auth is used.

adamkaplan added some commits
@adamkaplan adamkaplan Removed useless "&undefined=undefined" from URL parameters when no au…
…th key is provided
298c903
@adamkaplan adamkaplan Removed extraneous "?" from URL when no paramteres are supplied 6db92c9
@adamkaplan adamkaplan 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.
5e9f9d4
@mansilladev mansilladev merged commit f2796a6 into mashery:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 13, 2011
  1. @adamkaplan
  2. @adamkaplan
  3. @adamkaplan

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

    adamkaplan authored
    …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.
This page is out of date. Refresh to see the latest.
Showing with 9 additions and 4 deletions.
  1. +9 −4 app.js
View
13 app.js
@@ -298,14 +298,19 @@ 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;
+ 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
+ path: apiConfig.publicPath + methodURL + ((paramString.length > 0) ? '?' + paramString : "")
};
if (apiConfig.oauth) {
@@ -455,7 +460,7 @@ function processRequest(req, res, next) {
console.log('Unsecured Call');
// Add API Key to params, if any.
- if (apiKey != '') {
+ if (apiKey != '' && apiKey != 'undefined' && apiKey != undefined) {
options.path += '&' + apiConfig.keyParam + '=' + apiKey;
}
Something went wrong with that request. Please try again.