-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Endpoints accessed through /wp-json when using wp-env
return Not Found
#49373
Comments
/wp-json/
when using wp-env
return Not Foundwp-env
return Not Found
After some research I've found the answer below. This explains why the rest api routes aren't working, though is there a conventional way to enable permalinks through a script or configuration?
|
Found a solution to enable permalinks through cli, thank you @erikyo wp-env run cli "wp rewrite structure '/%postname%'" Which seemed like it was going to work. But still getting "Not Found". |
Resolved 🎉 In the comment above, we didn't formatted the wp-env run cli "wp rewrite structure /%postname%/" I believe this should be in the |
As far as I know, the REST API endpoint relies on the permalink setting, which is the expected behavior of WordPress. However, on Windows and Linux, |
Yes that's right: at first the WP deployment has "plain" permalinks as a structure but this is blocking us from using (for example) insomnia to test the rest-api and we are forced to login into WordPress and enable it. Wouldn't it be better to provide this kind of setting directly in the wp-env configuration so we can test the api without further "complications"? |
That might make sense. @johnhooks |
@t-hamano as a developer new to WordPress and being exposed to it by Gutenberg and block development, there is a large disconnect between the documentation of Gutenberg and WordPress. I believe there needs to be a note about the default behavior of the rest-api and permalinks. I went to the REST API Handbook, and opened strait to "Using the REST API" and the note about permalinks is in "Key Concepts", so I initially missed it. While that could be blamed on me for not reading it cover to cover, I believe key stumbling blocks like this should be identified and specifically repeated throughout the documentation, because it is not apparent. Styling it as a warning, not as information, would also help call it out.
I will close this issue with a PR to expand the documentation. @mburridge do you have any thoughts on how best to accomplish this? |
I think the default behavior of the rest-API and permalinks should be related to all WordPress environments, not just wp-env. Therefore, one idea might be to suggest moving the note about permalinks to a more obvious location in the GitHub repository of the REST API Handbook. However, in the Block Editor Handbook, it is explained as if the endpoint is naturally |
The key issue here, is the default behavior of WordPress is to not enable permalinks by default. Though everything in the REST API Handbook, except for that little note, assume permalinks are enabled. And I understand this isn't a Gutenberg issue, but I'm still unsure where or how to create an issue for the REST documentation. |
This is exactly the issue, all the documentation assumes permalinks. |
You can create non-Gutenberg documentation issues over in the WordPress/Documentation-Issue-Tracker repo. |
Thank you @mburridge, I will do that. Do you believe there is reason to include a note about this in the |
I think that would be a fab idea. 👌 |
Thank you, I will get it done. |
That would be awesome, I just stumbled into this yesterday and was scratching my head for a bit until I found this issue, getting it documented somewhere will definitely help, thanks! 👍 |
@eduwass out of curiosity, where did you look for an answer first? |
@johnhooks → https://developer.wordpress.org/block-editor/reference-guides/packages/packages-env/ That was my first destination! |
@eduwass that was not one of the locations on my radar. I'll add it to the list. |
Should we just make this the default for wp-env?
Also, I believe this file is updated automatically based on the |
I support enabling permalinks by default in |
The permissions side of this should be fixed, but we should still change the default behavior. |
I believe that #50251 largely addresses this, so am closing this issue. If re-opening in order to keep alive the issue of adding an option to the wp-env settings, or having pretty permalinks enabled by default, then please remove the Preferably open a new issue to change the default wp-env environment. |
@johnhooks Your solution above, $ npx wp-env run cli "wp rewrite structure /%postname%/"
ℹ Starting 'wp rewrite structure /%postname%/' on the cli container.
OCI runtime exec failed: exec failed: unable to start container process: exec: "wp rewrite structure /%postname%/": stat wp rewrite structure /%postname%/: no such file or directory: unknown
✖ Command failed with exit code 126
Command failed with exit code 126 Without quotes it appeared to work: $ npx wp-env run cli wp rewrite structure /%postname%/
ℹ Starting 'wp rewrite structure /%postname%/' on the cli container.
Success: Rewrite structure set.
Success: Rewrite rules flushed.
✔ Ran `wp rewrite structure /%postname%/` in 'cli'. (in 3s 443ms) But wasn't really: $ curl -I -s http://localhost:8888/wp-json/wp/v2/ | grep HTTP | grep -Eo "\d+" | tail -n 1
404 Adding $ npx wp-env run cli wp rewrite structure /%year%/%monthnum%/%postname%/ --hard
ℹ Starting 'wp rewrite structure /%year%/%monthnum%/%postname%/ --hard' on the cli container.
Success: Rewrite structure set.
Warning: Regenerating a .htaccess file requires special configuration. See usage docs.
Warning: Regenerating a .htaccess file requires special configuration. See usage docs.
Success: Rewrite rules flushed.
✔ Ran `wp rewrite structure /%year%/%monthnum%/%postname%/ --hard` in 'cli'. (in 4s 437ms) Which I fixed by adding a apache_modules:
- mod_rewrite And mapping that in my {
...
"mappings": {
"wp-cli.yml": "./wp-cli.wp-env.yml"
},
...
} Although that's only worked for $ curl -I -s "http://localhost:8889/wp-json/wp/v2/" | grep HTTP | grep -Eo "\d+" | tail -n 1
404 Where the solution required using the $ npx wp-env run tests-cli wp rewrite structure /%year%/%monthnum%/%postname%/ --hard
ℹ Starting 'wp rewrite structure /%year%/%monthnum%/%postname%/ --hard' on the tests-cli container.
Success: Rewrite structure set.
Success: Rewrite rules flushed.
✔ Ran `wp rewrite structure /%year%/%monthnum%/%postname%/ --hard` in 'tests-cli'. (in 6s 184ms)
$ curl -I -s "http://localhost:8889/wp-json/wp/v2/" | grep HTTP | grep -Eo "\d+" | tail -n 1
200 Adding that to my {
...
"lifecycleScripts": {
"afterStart": "wp-env run tests-cli wp rewrite structure /%year%/%monthnum%/%postname%/ --hard"
}
} Seems to have worked well: $ echo Y | npx wp-env destroy
ℹ WARNING! This will remove Docker containers, volumes, networks, and images associated with the WordPress instance.
? Are you sure you want to continue? Yes
✔ Removed WordPress environment. (in 28s 572ms)
$ npx wp-env start
WordPress development site started at http://localhost:8888
WordPress test site started at http://localhost:8889
MySQL is listening on port 59065
MySQL for automated testing is listening on port 59130
✔ Done! (in 106s 660ms)
$ curl -I -s "http://localhost:8889/wp-json/wp/v2/" | grep HTTP | grep -Eo "\d+" | tail -n 1
200 Thanks for the help. |
here is offcial doc for reference |
Why do all the REST API endpoints accessed through
/wp-json/wp/v2
of thewp-env
server return a HTML response of "Not Found".In this closed issue, the solution provided is less than ideal:
#22648
Is there a specific limitation of
wp-env
that prevents the correct routing?The text was updated successfully, but these errors were encountered: