-
Notifications
You must be signed in to change notification settings - Fork 42
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
wp-now: Error on stackblitz.com #79
Comments
I am really eager to see this work as well. I made a fork
As I said, I would really like to get it running. I have a class coming next term that I would like to use with stackblitz. |
I have an express server that works for a get on stackblitz, using @php-wasm/node: import express from 'express';
import { NodePHP } from '@php-wasm/node';
const app = express();
app.get(/\.php$/, async (req, res) => {
const php = await NodePHP.load('8.2', {
emscriptenOptions: {
ENV: {
...process.env,
TERM: 'xterm',
},
},
});
php.useHostFilesystem();
let sUrl = req.path;
if (sUrl[sUrl.length - 1] == '/') {
sUrl += 'index.php';
}
sUrl = sUrl.replace(/^\//, '');
const args = [sUrl];
const originalStdoutWrite = process.stdout.write.bind(process.stdout);
process.stdout.write = (chunk) => {
res.write(chunk);
};
await php.cli(['php', ...args]);
res.end();
process.stdout.write = originalStdoutWrite;
});
const server = app.listen(3001, () =>
console.log(`listening on ${server.address().port}`)
); |
I have the feeling that it won't work for post unless we use the cgi version of php. Will dig in to that next. |
@rhildred thank you so much for sharing all these useful details!
Interesting! What makes the CGI version special here? |
the post variables are in the request body (written to stdin after a blank line and the headers) according to the CGI spec. I was thinking that the php cli doesnt' read from stdin. When I read the docs, I see that the cli does read from php://stdin. The request headers are encoded as environment variables in the spec so maybe I am wrong. I am away until Wednesday, so I will check after that. |
@rhildred You seem to be running into this issue: WordPress/wordpress-playground#416 About CGI and to clarify how Playground works. Playground uses a custom SAPI, see php_wasm.c. Request body is passed from JavaScript using the internal #setRequestBody method. |
Wow! #setRequestBody could be a project saver! I am just getting back to it now. I really had hoped to be ready to launch my browser based prototyping product and be in selling mode now. A quick win with wordpress would be a big help right now. I also have students that need it for a class next (January) term. |
I found out how wp.run uses wp.#setRequestBody and got it working with wp.run on stackblitz and on vslite.dev. Now it comes with a php error:
the working code is mostly taken from startServer.ts:
|
@schlessera and I tried running
wp-now
on Stackblitz, but it failed with the following error. My guess is it attempted to make a network connection but Stackblitz doesn't support those:The same command worked in
@php-wasm/cli
so it's not a Playground issue.The text was updated successfully, but these errors were encountered: