Skip to content

Commit

Permalink
Merge pull request #11 from Automattic/add/v2-support
Browse files Browse the repository at this point in the history
Add support for WP-API /wp-json endpoints.
  • Loading branch information
retrofox committed Feb 11, 2016
2 parents 77701ea + 4b9ed9d commit 7b1faa8
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ var proxyOrigin = 'https://public-api.wordpress.com';

var defaultApiVersion = '1';

/**
* WP-API Versions
*/
var wpApiVersions = ['2'];

/**
* Performs an XMLHttpRequest against the WordPress.com REST API.
*
Expand All @@ -48,7 +53,14 @@ function request (params, fn) {
proxyOrigin = params.proxyOrigin || proxyOrigin;
delete params.proxyOrigin;

var url = proxyOrigin + '/rest/v' + apiVersion + params.path;
var basePath = '/rest/v' + apiVersion;

// if this is a wp-api request, adjust basePath
if ( wpApiVersions.indexOf( apiVersion ) !== -1 ) {
basePath = '/wp-json';
}

var url = proxyOrigin + basePath + params.path;
debug('API URL: %o', url);
delete params.path;

Expand Down

0 comments on commit 7b1faa8

Please sign in to comment.