Skip to content

Commit

Permalink
Add support for WP-API /wp-json endpoints.
Browse files Browse the repository at this point in the history
  • Loading branch information
timmyc committed Feb 11, 2016
1 parent 77701ea commit 4b9ed9d
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 4b9ed9d

Please sign in to comment.