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

Update: Simplify base-php sapi_handle_request call #387

Merged

Conversation

kozer
Copy link
Contributor

@kozer kozer commented May 18, 2023

What?

We decided to split #331 into two parts, to make changes clear.
Part 1 of #331

Part 2 is #388

This pr simplifies the logic of #handleRequest method by removing unnecessary async wrapping

Why?

It was originally introduced in #331, where a 404 page for nonexisting files was introduced, in order to simplify things.

For more info, look at #331

How?

  • By removing the async function. async functions return a promise by themselves and also resolve method is able to resolve nested promises if they returned correctly. So the original async function wasn't really necessary

Testing Instructions

N/A

@kozer kozer requested review from adamziel and danielbachhuber May 18, 2023 13:06
@kozer kozer self-assigned this May 18, 2023
@kozer kozer mentioned this pull request May 18, 2023
Copy link
Member

@danielbachhuber danielbachhuber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this PR is going in the commit history, it would be great to have a full pull request description for it.

packages/php-wasm/node/src/test/php.spec.ts Show resolved Hide resolved
@danielbachhuber danielbachhuber merged commit 72221a5 into WordPress:trunk May 18, 2023
@danielbachhuber danielbachhuber deleted the update/simplify_php_base branch May 18, 2023 13:33
kozer added a commit that referenced this pull request May 18, 2023
<!-- Thanks for contributing to WordPress Playground! -->

## What?

This pr adds a 404 error if the requested path doesn't exist

<!-- In a few words, what is the PR actually doing? Include screenshots
or screencasts if applicable -->
We decided to split #331 into two parts, to make changes clear.
Part 2 of #331

Part 1 is #387

## Why?

When the user uses a path that doesn't have any files, the `wp-now` was
throwing an error, and was no longer usable.
This pr fixes that.

Also, take a look at #331 

<!-- Why is this PR necessary? What problem is it solving? Reference any
existing previous issue(s) or PR(s), but please add a short summary
here, too -->

## How?

When we call `php.run` method, we build the `scriptPath` using
`resolvePHPFilePath`. If the file is not there we assume that an
`/index.php` file exists in the folder.

This is not correct, and we need to return a 404 `PhpRequest`.

Also, take a look at #331 

<!-- How is your PR addressing the issue at hand? What are the
implementation details? -->

## Testing Instructions

- Create an empty folder
- Run wp-now and make sure you add this folder as a path: npx nx preview
wp-now start --path=<your-empty-folder>
- Ensure that you don't see any errors in the console
- Ensure that you see 404 File not found in the browser
- Change the URL to something else. eg: /file-not-exist.php.
- Ensure that you still see 404 File not found
adamziel added a commit that referenced this pull request May 18, 2023
@adamziel
Copy link
Collaborator

@danielbachhuber the commit message for this one wasn't quite there. I re-applied it with a small writeup to explain the entire context behind the change:

1a31776

I know I'm pushing hard on this one. This is the most important code path in the entire codebase and I want to make sure the change history is extremely clear for the next person debugging it.

@danielbachhuber
Copy link
Member

@adamziel Cool, sounds good.

Pookie717 added a commit to Pookie717/wordpress-playground that referenced this pull request Oct 1, 2023
<!-- Thanks for contributing to WordPress Playground! -->

## What?

This pr adds a 404 error if the requested path doesn't exist

<!-- In a few words, what is the PR actually doing? Include screenshots
or screencasts if applicable -->
We decided to split #331 into two parts, to make changes clear.
Part 2 of WordPress/wordpress-playground#331

Part 1 is WordPress/wordpress-playground#387

## Why?

When the user uses a path that doesn't have any files, the `wp-now` was
throwing an error, and was no longer usable.
This pr fixes that.

Also, take a look at #331 

<!-- Why is this PR necessary? What problem is it solving? Reference any
existing previous issue(s) or PR(s), but please add a short summary
here, too -->

## How?

When we call `php.run` method, we build the `scriptPath` using
`resolvePHPFilePath`. If the file is not there we assume that an
`/index.php` file exists in the folder.

This is not correct, and we need to return a 404 `PhpRequest`.

Also, take a look at #331 

<!-- How is your PR addressing the issue at hand? What are the
implementation details? -->

## Testing Instructions

- Create an empty folder
- Run wp-now and make sure you add this folder as a path: npx nx preview
wp-now start --path=<your-empty-folder>
- Ensure that you don't see any errors in the console
- Ensure that you see 404 File not found in the browser
- Change the URL to something else. eg: /file-not-exist.php.
- Ensure that you still see 404 File not found
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants