Fix opening files from Ignition error page #576
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 thePWD
environment variable in thedocker-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 theServeCommand
. Therefore this PR depends upon laravel/framework#46857 to work properly, which addsIGNITION_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
follow the installation instructions
change the contents of
routes/web.php
to throw an exceptionand 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 yourvendor/
folder.Opening files by clicking on the link should work again now:
after.mov