Skip to content

Commit

Permalink
Improve use of WP Playground CORS proxy (#182)
Browse files Browse the repository at this point in the history
* Local blueprint needs to explicitly override constant and uses old schema

* Provide correct host
  • Loading branch information
chriszarate authored Oct 28, 2024
1 parent 3d20135 commit a4c1c71
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
8 changes: 7 additions & 1 deletion blueprint.local.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,18 @@
"blogdescription": "Explore the Remote Data Blocks plugin in a WordPress Playground"
}
},
{
"step": "defineWpConfigConsts",
"consts": {
"USE_PLAYGROUND_CORS_PROXY": false
}
},
{
"step": "installPlugin",
"options": {
"activate": true
},
"pluginData": {
"pluginZipFile": {
"resource": "wordpress.org/plugins",
"slug": "query-monitor"
}
Expand Down
10 changes: 8 additions & 2 deletions inc/HttpClient/WPRemoteRequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,14 @@ public function __invoke( RequestInterface $request, array $options ): PromiseIn
$url = (string) $request->getUri();

// If we are running on WordPress Playground, use the provided CORS proxy.
if ( defined( 'USE_PLAYGROUND_CORS_PROXY' ) && USE_PLAYGROUND_CORS_PROXY ) {
$url = 'https://playground.wordpress.net/cors-proxy.php?' . $url;
if ( defined( 'USE_PLAYGROUND_CORS_PROXY' ) && true === USE_PLAYGROUND_CORS_PROXY ) {
$new_uri = $request->getUri()
->withHost( 'playground.wordpress.net' )
->withScheme( 'https' )
->withPath( '/cors-proxy.php' )
->withQuery( $url );
$request = $request->withUri( $new_uri );
$url = (string) $new_uri;
}

$args = [
Expand Down

0 comments on commit a4c1c71

Please sign in to comment.