Skip to content
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

REST API not working with wp-now #367

Open
ivanjeremic opened this issue Jan 9, 2025 · 6 comments
Open

REST API not working with wp-now #367

ivanjeremic opened this issue Jan 9, 2025 · 6 comments

Comments

@ivanjeremic
Copy link

Any requests to http://localhost:8881/wp-json/ gives the error:

Error creating or updating page: HTTP error! status: 401

How would we enable a rest API that allows requests?

@bgrgicak
Copy link
Collaborator

Hey @ivanjeremic
Could you please share a bit more info. Is this related to WP-now?
Do you maybe have a Blueprint that we could use to recreate it?

Have you enabled pretty permalinks on your site?

For sites without “pretty permalinks” enabled, /wp-json/ isn’t automatically handled by WordPress. This means that normal/default WordPress permalinks will be used instead.

https://developer.wordpress.org/rest-api/using-the-rest-api/discovery/#link-header

@ivanjeremic
Copy link
Author

ivanjeremic commented Jan 10, 2025

Is this related to WP-now?
Yes.

Do you have a Blueprint that we could use to recreate it?
No, I use the default options.

Have you enabled pretty permalinks on your site?
Yes, I have enabled them.

Enabling permalinks was the first thing I did, but I still haven't had any success. I can query the wp-json API without any problems, but posting to it and adding or changing data is impossible for some reason, which is almost a deal breaker for a local dev tool.

I tested on multiple systems, Windows 10, 11 & WSL2 everywhere the same issue.

I think it could be related to Link

@brandonpayton
Copy link
Member

I believe this is the same issue as
WordPress/wordpress-playground#1611

And there is a fix to the underlying problem proposed here:
WordPress/wordpress-playground#2110

If that fix is merged, then wp-now would need to be upgraded to use the latest Playground packages in order to receive the fix.

@ivanjeremic
Copy link
Author

I believe this is the same issue as WordPress/wordpress-playground#1611

Yes, this is it, was not able to find this issue before. Hope that a fix will be here soon because using rest API is very common. I also read in the issue that wp-now is not the future but instead the @wp-playground/cli does that work similarly to wp-now and does not require any docker? I can't find any docs on it.

@brandonpayton
Copy link
Member

I could be wrong but am not sure there are any dedicated docs yet. It is built similarly to wp-now though there are some differences. And it also does not require Docker.

You can play with it with Node.js 20.x+ (maybe older versions work, but I had some trouble with Node.js 18.x):

npx @wp-playground/cli server

To see the command line options:

npx @wp-playground/cli --help

AFAIK, the biggest differences between wp-now and the official Playground CLI package is that the official package does not yet include logic to guess what kinds of directories you are giving it (like a plugin dir or wp-content). I believe we'd like to support those features in Playground CLI as well, but for now, it is necessary to explicitly mount directories where you want them.

The FS structure within Playground includes a /wordpress directory at the root, so if you want to mount a local plugin dir within playground you would do something like:

npx @wp-playground/cli server --mount "<local-plugin-dir>:/wordpress/wp-content/plugins/<plugin-name>"

where <local-plugin-dir> and <plugin-name> are substituted for actual values.

Does that help?

@ivanjeremic
Copy link
Author

@brandonpayton I tested @wp-playground/cli server now on multiple systems (W11/WSL2) but I have to say @wp-now/wp-now feels more usable for now.

WSL 2 issues:

I have some weird bugs with the @wp-playground/cli server, navigating to any path like the Sample Page or the Admin dashboard does not work and results in the error ERR_CONNECTION_REFUSED also there is a weird styling bug on the main page which is the only page you are able to see when the server starts. Here an screenshot.

Image

WIN 11 issues:

Here I was not able to get it working in any way

failed to asynchronously prepare wasm: Error: ENOENT: no such file or directory, open 'C:\C:\Users\ivj\wpcli\node_modules\@php-wasm\node\asyncify\8_0_30\php_8_0.wasm'
Error: ENOENT: no such file or directory, open 'C:\C:\Users\ivj\wpcli\node_modules\@php-wasm\node\asyncify\8_0_30\php_8_0.wasm'
    at Object.openSync (node:fs:562:18)
    at Object.readFileSync (node:fs:446:35)
    at read_ (file:///C:/Users/ivj/wpcli/node_modules/@php-wasm/node/index.js:86553:17)
    at readBinary (file:///C:/Users/ivj/wpcli/node_modules/@php-wasm/node/index.js:86556:17)
    at getBinarySync (file:///C:/Users/ivj/wpcli/node_modules/@php-wasm/node/index.js:86720:14)
    at file:///C:/Users/ivj/wpcli/node_modules/@php-wasm/node/index.js:86732:21
    at ReadFileContext.callback (file:///C:/Users/ivj/wpcli/node_modules/@php-wasm/node/index.js:86566:11)
    at FSReqCallback.readFileAfterOpen [as oncomplete] (node:fs:299:13) {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'open',
  path: 'C:\\C:\\Users\\ivj\\wpcli\\node_modules\\@php-wasm\\node\\asyncify\\8_0_30\\php_8_0.wasm'
}
Aborted(Error: ENOENT: no such file or directory, open 'C:\C:\Users\ivj\wpcli\node_modules\@php-wasm\node\asyncify\8_0_30\php_8_0.wasm')
file:///C:/Users/ivj/wpcli/node_modules/@php-wasm/node/index.js:86701
    var e = new WebAssembly.RuntimeError(what);
            ^

RuntimeError: Aborted(Error: ENOENT: no such file or directory, open 'C:\C:\Users\ivj\wpcli\node_modules\@php-wasm\node\asyncify\8_0_30\php_8_0.wasm'). Build with -sASSERTIONS for more info.
    at abort (file:///C:/Users/ivj/wpcli/node_modules/@php-wasm/node/index.js:86701:13)
    at file:///C:/Users/ivj/wpcli/node_modules/@php-wasm/node/index.js:86744:7

Node.js v22.13.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Inbox
Development

No branches or pull requests

3 participants