jeremiah-shaulov / deno_fcgi

FastCGI implementation for Deno
MIT License
8 stars 0 forks source link

Difficulties POST-ing to WordPress fpm docker image. #2

Open EarthlingDavey opened 2 weeks ago

EarthlingDavey commented 2 weeks ago

Hi jeremiah 👋

This looks like a cool project, I gave it a spin but I could not get POST data to go to WordPress.

No matter what I tried, $_POST was always empty according to php.

Here's a snippet of what I tried:

const uri = '.php' === ext ? path.relative('/', pathname) : 'index.php';

const params = {
  DOCUMENT_URI: `/${uri}`,
  REQUEST_URI: `/${uri}`,
  SCRIPT_NAME: `/${uri}`,
  GATEWAY_INTERFACE: 'CGI/1.1',
  REDIRECT_STATUS: '200',
};

try {
  const resp = await fcgi.fetch(
    {
      addr: 'localhost:9020',
      scriptFilename: `${DOCUMENT_ROOT}/${uri}`,
      params: new Map(Object.entries(params)),
      onLogError: console.error,
    },
    new Request(ctx.request.url.href, {
      method: ctx.request.method,
      headers: ctx.request.headers,
      // No matter what I have here, stream form data, manually entered text string, php never sees $_POST
      body: ctx.request.hasBody ? await ctx.request.body().value : undefined,
    })
  );
  ctx.response.status = resp.status;
  ctx.response.headers = resp.headers;
  ctx.response.body = resp.body;
} catch (e) {
  console.error(e);
}

Do you have any insight or tips on debugging?

jeremiah-shaulov commented 14 hours ago

Hi! Thank you for your feedback. Indeed there was such bug. I fixed it in v2.0.5.

EarthlingDavey commented 8 hours ago

No problem and thank you for fixing it brother ✌️