Skip to content

[13.x] Handle api / json routes with Down (Maintenance) command#60595

Merged
taylorotwell merged 3 commits into
laravel:13.xfrom
davidrushton:feature/maintenance-ignore-paths
Jun 30, 2026
Merged

[13.x] Handle api / json routes with Down (Maintenance) command#60595
taylorotwell merged 3 commits into
laravel:13.xfrom
davidrushton:feature/maintenance-ignore-paths

Conversation

@davidrushton

Copy link
Copy Markdown
Contributor

On our application we occasionally use --render or --redirect with maintenance mode during scheduled maintenance. For example php artisan down --render=errors.503-scheduled shows a pre-planned maintenance template rather than the application default (unexpected outage).

The issue is that the Laravel storage/framework/maintenance.php file always spits that out, regardless if the client (in this case our mobile app) is expecting JSON rather than HTML.

This would be the same if a redirect was intended for web and would break API / mobile clients that are expecting JSON.

This PR adds an --ignore=* option to the DownCommand. Paths or patterns here will skip the storage/framework/maintenance.php catch and instead refer to the framework PreventRequestsDuringMaintenance middleware. This will only render the template if the request path is not in the ignore array. Tested this works as expected by returning JSON on api/users and the custom view on / when I run:

php artisan down --render=errors.503-scheduled --ignore="api/*"

Note: This merges both ignore and except into the data['except'] (down file) to avoid a non-framework Laravel change / upgrade.

@davidrushton davidrushton changed the title Handle api / json routes with Down (Maintenance) command [13.x] Handle api / json routes with Down (Maintenance) command Jun 26, 2026
@shaedrich

Copy link
Copy Markdown
Contributor

Shouldn't Expect: application/json just get some JSON like

{
    "message": "Request cannot be processed during maintenance mode. Please try again later."
}

?

@davidrushton

Copy link
Copy Markdown
Contributor Author

Shouldn't Expect: application/json just get some JSON like

{

    "message": "Request cannot be processed during maintenance mode. Please try again later."

}

?

The framework already returns appropriate json when maintenance mode is on, but only if you're not setting a custom view or redirect when running the down command (it doesn't hit the framework in these cases regardless of the request type or prefix)

My thoughts were - let the framework handle the response if the path is in the ignore option / array.

@taylorotwell

Copy link
Copy Markdown
Member

Instead of adding a new --ignore option, I think Laravel should automatically do the right thing based on the type of request. Custom maintenance pages and redirects are mainly meant for browser visitors, while API or mobile clients usually expect a JSON response.

Updated the PR so that browser users still see the custom maintenance page or redirect, but requests asking for JSON get Laravel’s normal JSON 503 maintenance response instead. This avoids making developers configure path patterns like api/*.

@taylorotwell taylorotwell merged commit 66844c4 into laravel:13.x Jun 30, 2026
53 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.

3 participants