Comments (8)
This looks like a CORS issue to me.
Because Playground runs in a browser it can only send requests to servers that allow CORS requests. A typical PHP server doesn't have this restriction.
I verified your domain api.laolaweb.com
and it doesn't allow CORS requests. Here is a link to a CORS tester that confirms it.
You can also test this by executing a fetch request in your browser console await fetch('https://api.laolaweb.com');
.
This is similar to what Playground does in the background.
To resolve this you will need to add CORS support to your server, or create a proxy server that supports CORS and route your requests through it if you can't modify CORS headers on your API server.
I'm closing this issue as it doesn't seem like there is anything we can do in Playground, but please feel free to keep commenting here, I'm happy to help.
from wordpress-playground.
Thank you for your support. I think this issue will also help others who are facing exactly the same challenge. By the way, I only had to add the following on my server before every other issue to solve this:
if( 'OPTIONS' === $_SERVER['REQUEST_METHOD'] ) {
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE');
header("Access-Control-Allow-Headers: $_SERVER[HTTP_ACCESS_CONTROL_REQUEST_HEADERS]");
header("Content-Length: 0");
header("Content-Type: text/plain");
exit;
}
from wordpress-playground.
Linking to #772 as variations of this issue come up frequently. We should find a way of telling the developer what went wrong, it could even be an mu-plugin that overrides window.fetch with a version that logs an extra error message discussing CORS. Ideally, every popular gotcha would log a clear message providing a clear way forward without going through GitHub issues. @bgrgicak would you please start a new high-priority issue to track that? FYI @brandonpayton
from wordpress-playground.
Where does this message come from?
The message comes from this catch code.
How can I recreate this error using your plugin?
Would you be able to share your blueprint with us?
from wordpress-playground.
And why is an OPTIONS request being sent here instead of the actual POST?
I assume that these are CORS preflight requests.
The plugin establishes an HTTP connection for a translation of texts in the website to a PHP script I developed for this purpose, which serves as a proxy for the actual API-interface.
Do you see any CORS errors in the browser console when this request is made?
If I understood correctly your plugin is making requests to a server. Does this server have CORS enabled?
from wordpress-playground.
Would you be able to share your blueprint with us?
Sure, look here: https://plugins.svn.wordpress.org/easy-language/assets/blueprints/blueprint.json
Do you see any CORS errors in the browser console when this request is made?
Yes, I see an error message there relating to CORS. But only in the Playground - it doesn't occur in a normal WordPress installation.
from wordpress-playground.
But only in the Playground - it doesn't occur in a normal WordPress installation.
That's expected. If a server requests files from an endpoint, CORS permissions don't apply to it.
If a browser does it, it checks for CORS permissions first and stops the requests if the permissions are set to deny.
I edited the blueprint you shared to include your plugin:
{
"landingPage": "/wp-admin/admin.php?page=easy_language_settings",
"preferredVersions": {
"php": "8.2",
"wp": "latest"
},
"features": {
"networking": true
},
"steps": [
{
"step": "installPlugin",
"pluginZipFile": {
"resource": "wordpress.org/plugins",
"slug": "easy-language"
},
"options": {
"activate": true
}
},
{
"step": "login",
"username": "admin",
"password": "password"
},
{
"step": "mkdir",
"path": "/wordpress/wp-content/languages/plugins"
},
{
"step": "mkdir",
"path": "/wordpress/wp-content/languages/themes"
},
{
"step": "writeFile",
"path": "/wordpress/wp-content/languages/de_DE.mo",
"data": {
"resource": "url",
"caption": "Downloading de_DE.mo",
"url": "https://translate.wordpress.org/projects/wp/dev/de/default/export-translations?format=mo"
}
},
{
"step": "writeFile",
"path": "/wordpress/wp-content/languages/admin-de_DE.mo",
"data": {
"resource": "url",
"caption": "Downloading admin-de_DE.mo",
"url": "https://translate.wordpress.org/projects/wp/dev/admin/de/default/export-translations?format=mo"
}
},
{
"step": "setSiteOptions",
"options": {
"WPLANG": "de_DE"
}
}
]
}
When I run it on Playground
there is a CORS error for this endpoint https://api.wordpress.org/themes/update-check/1.1/
.
Is this the CORS error you are referring to? If not, what is the is the request URL and how can I trigger this request using this Playground link?
from wordpress-playground.
First of all, thank you for your support and for your questions.
The CORS messages that you see immediately after setup are actually not my problem. Once the Playground is loaded, go to "Seiten" (ala Pages) and click on one of the "+" icons in the table. In the dialog that opens, click on the blue "Simplify now with..." button. At that moment, a request is triggered via AJAX and sent to my proxy (external URL starting with https://api.laolaweb.com
). This is exactly what arrives at my server with the HTTP method OPTIONS - unlike when I do this with a WordPress installation outside the Playground (the post-request arrives directly, which is also expected from me). You can't see it in the console, sorry for the confusion at first.
EDIT: Incidentally, the request is sent via wp_safe_remote_post().
from wordpress-playground.
Related Issues (20)
- Boot protocol HOT 1
- Remove NodePHP and WebPHP classes
- HTTP POST request to rest endpoint returning Host is unreachable HOT 3
- Website: Pre-gzipped `wp-cli.phar.gz` does not satisfy requests for `wp-cli.phar` HOT 1
- PR not loading in Playground. Giving Error: Could not unlink "temp/pr.zip" HOT 3
- wpCLI via JS API returns "Hello World!" HOT 1
- Helper Functions to Manage php.ini Entries HOT 1
- wp_remote_post Content-Type header not respected HOT 1
- Optionally do not use playground frame HOT 2
- Website: Default to OPFS storage HOT 1
- Add CORS error message to PHP requests
- Import WXR step: Fails when importing audio metadata HOT 3
- Improving "Export Pull Request to Github" functionality
- Import WXR: Post authors not mapping
- Update blueprint builder to include $schema and remove some unnecessary entries.
- Error modal doesn't show WordPress debug logs HOT 4
- Website: Deploy does not properly set aside files that need custom redirects HOT 5
- SQL and JS errors with Yoast SEO HOT 15
- Rotate PHP runtime on crash so it can continue to satisfy subsequent requests HOT 2
- Enable networking for WordPress PR viewer
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wordpress-playground.