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

Fix opening files from Ignition error page #576

Merged
merged 1 commit into from
Apr 24, 2023
Merged

Fix opening files from Ignition error page #576

merged 1 commit into from
Apr 24, 2023

Conversation

NiclasvanEyk
Copy link
Contributor

The Ignition error page has a feature where you can open the file where an error occurred in your preferred IDE, simply by clicking on a link. However, as you can see in my demonstration video below, this feature does not work out of the box when using Docker (at least with Sail's current setup), since Ignition does not know where the project resides on the host machine and generates links to /var/www/html:

before.mov

To support this scenario, Ignition allows you to define the IGNITION_LOCAL_SITES_PATH environment variable (docs), which you can use to configure the path to the project on the host machine, thereby fixing the link generation.

This PR sets IGNITION_LOCAL_SITES_PATH to the current working directory based on the PWD environment variable in the docker-compose.yml. This way Ignition's link generation just works when using Sail.

Caveats

Relying on the PWD environment variable is not perfect.
You could start your compose services from outside the project directory, by e.g. running example-app/vendor/bin/sail -f example-app/docker-compose.yml up. In this case, wrong links are generated, but I think supporting this edge case is not worth the effort.

Since this PR passes IGNITION_LOCAL_SITES_PATH as a real system envirnoment variable and not through a.env file, it does not automatically get passed to the PHP server process by the ServeCommand. Therefore this PR depends upon laravel/framework#46857 to work properly, which adds IGNITION_LOCAL_SITES_PATH to the list of environment variables passed to PHP by default.

I tested the fix on Linux and MacOS and can confirm that it works. I don't have access to a computer running Windows, and don't know if this fix works in WSL.

Reproduction Steps

curl -s "https://laravel.build/example-app" | bash

follow the installation instructions

cd example-app && vendor/bin/sail up

change the contents of routes/web.php to throw an exception

Route::get('/', function () {
    throw new \Exception("Whoops!");

    return view('welcome');
});

and visit http://localhost in the browser.
You should now be able to reproduce the behavior shown in the screen recording.

Then adjust the contents of docker-compose.yml to those of this PR and restart Sail.
Also make sure to apply the changes of laravel/framework#46857 to the ServeCommand in your vendor/ folder.

Opening files by clicking on the link should work again now:

after.mov

Enables Ignition to open files where an error occurred.
@taylorotwell taylorotwell merged commit 076fd9f into laravel:1.x Apr 24, 2023
4 checks passed
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.

None yet

2 participants