Maintenance mode --render option vs. json requests
aedart opened this issue · 0 comments
The "new" --render
argument for artisan down
command does it's job well, by rendering whatever template has been requested. Sadly, when using this option it appears that API requests (requests that have Accept: application/json
header set) are not handled correctly.
The framework usually deals with this automatically, when not using the --render
option. But, when running composer install / update in the background, some requests might actually lead to an "Internal Server Error", because parts of the framework / vendor has yet to be installed by composer. So, the new pre-rendering of view makes a lot of sense. But it would be really nice if pre-rendering / maintenance mode could somehow take API requests into account.
Possible Solution A
The generated storage/framework/maintenance.php
could check for Accept: application/json
headers (or variants hereof) and ensure NOT to output html, if such is the case.
Possible Solution B
Add a --resolve-via
argument to the artisan down
that accepts a php file path. This file could then be used instead of the maintenance.php
file, allowing developer to resolve maintenance mode however they wish.
Note: this does differ from the --render
in that pre-rendered blade templates or php files do not have access to the http headers of the current request (at least not according to my knowledge / experiments).