Repository navigation
[Website] Enable CORS proxy for all fetches - #2076
Merged
Merged
Conversation
Replaces the regular `fetch()` call with a custom `fetchWithCorsProxy()` in:
* TLS network bridge
* URL Blueprint resources
* fetch network transport
This gives WordPress running inside Playground more access to cross origin
resources. It is still limited by the proxy itself, in particular around
the supported headers, content types, and allowed transfer sizes.
## Implementation
`fetchWithCorsProxy(url, requestOptions, corsProxyUrl)` starts with a regular `fetch(url)`. If it succeeds,
we're good. If it fails, it retries, but this time it goes through the
CORS proxy: `fetch(\`${corsProxyUrl}${url}\`)`. This applies to all the
requests initiated either by WordPress or by the provided Blueprint.
## Testing
Go to the URL below. Confirm the output is `int(<large number>)` and the
network tools ran two requests:
```
http://127.0.0.1:5400/website-server/#{%22landingPage%22:%22/curl-test.php%22,%22features%22:{%22networking%22:true},%22steps%22:[{%22step%22:%22writeFile%22,%22path%22:%22/wordpress/curl-test.php%22,%22data%22:%22%3C?php\n\t\t\t\t\t$ch%20=%20curl_init();\n\t\t\t\t\tcurl_setopt($ch,%20CURLOPT_URL,%20\%22https://adamadam.blog\%22);\n\t\t\t\t\tcurl_setopt($ch,%20CURLOPT_TCP_NODELAY,%200);\n\t\t\t\t\tcurl_setopt($ch,%20CURLOPT_RETURNTRANSFER,%201);\n\t\t\t\t\t$result%20=%20curl_exec($ch);\n\t\t\t\t\tcurl_close($ch);\n\t\t\t\t\tvar_dump(\n\t\t\t\t\t\tstrlen(\n\t\t\t\t\t\t\t$result\n\t\t\t\t\t\t)\n\t\t\t\t\t);\n\t\t\t\t%22}]}
```
Go to the URL below, confirm it opens the homepage of my blog
https://adamadam.blog:
```
http://127.0.0.1:5400/website-server/#{%20%22landingPage%22:%20%22/test.html%22,%20%22steps%22:%20[%20{%20%22step%22:%20%22writeFile%22,%20%22path%22:%20%22/wordpress/test.html%22,%20%22data%22:%20{%20%22resource%22:%20%22url%22,%20%22url%22:%20%22https://adamadam.blog%22%20}%20}%20]%20}
```
Go to the URL below, confirm it opens the homepage of my blog:
```
http://127.0.0.1:5400/website-server/#{%20%22landingPage%22:%20%22/test.html%22,%20%22features%22:%20{%20%22networking%22:%20true%20},%20%22constants%22:%20{%20%22WP_DEBUG%22:%20true,%20%22WP_SCRIPT_DEBUG%22:%20true,%20%22WP_DEBUG_DISPLAY%22:%20true%20},%20%22steps%22:%20[%20{%20%22step%22:%20%22runPHP%22,%20%22code%22:%20%22%3C?php%20require%20'/wordpress/wp-load.php';%20file_put_contents('/wordpress/test.html',%20wp_remote_retrieve_body(wp_safe_remote_get('https://adamadam.blog')));%22%20}%20]%20}
```
This was referenced Dec 13, 2024
fellyph
pushed a commit
to WordPress/blueprints
that referenced
this pull request
Jul 31, 2025
Since WordPress/wordpress-playground#2076 the proxy is no longer needed and in fact breaks the feed fetching.
2 tasks
This was referenced Apr 28, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Enables CORS proxy for all WordPress and Playground requests by replacing the regular
fetch()call with a customfetchWithCorsProxy()in:This gives WordPress running inside Playground more access to cross origin resources. It is still limited by the proxy itself, in particular around the supported headers, content types, and allowed transfer sizes.
Implementation
fetchWithCorsProxy(url, requestOptions, corsProxyUrl)starts with a regularfetch(url). If it succeeds, we're good. If it fails, it retries, but this time it goes through the CORS proxy:fetch(\${corsProxyUrl}${url}`)`. This applies to all the requests initiated either by WordPress or by the provided Blueprint.Testing
Go to the URL below. Confirm the output is
int(<large number>)and the network tools ran two requests:Go to the URL below, confirm it opens the homepage of my blog https://adamadam.blog:
Go to the URL below, confirm it opens the homepage of my blog: