Skip to content

Commit

Permalink
Use WordPress Playground CORS proxy (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
chriszarate authored Oct 23, 2024
1 parent b2ea705 commit eaa0115
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 6 additions & 0 deletions blueprint.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
"blogdescription": "Explore the Remote Data Blocks plugin in a WordPress Playground"
}
},
{
"step": "defineWpConfigConsts",
"consts": {
"USE_PLAYGROUND_CORS_PROXY": true
}
},
{
"step": "installPlugin",
"options": {
Expand Down
8 changes: 7 additions & 1 deletion inc/HttpClient/WPRemoteRequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ class WPRemoteRequestHandler {
public function __invoke( RequestInterface $request, array $options ): PromiseInterface {
try {
// Convert Guzzle request to arguments for wp_remote_request.
$url = (string) $request->getUri();
$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;
}

$args = [
'body' => (string) $request->getBody(), // Stream has been read, let __toString() rewind and read it.
'headers' => [],
Expand Down

0 comments on commit eaa0115

Please sign in to comment.