

RewriteRule ^(.*)$ maintenance/$1 symfony-app/.htaccess header("HTTP/1.1 503 Service Unavailable") Įcho file_get_contents('maintenance.html') We can do this with a redirect condition that validates the environment variable: RewriteCond % !^/maintenance/ When it's set to true (the string, not the boolean), we want to use the maintenance mode. This can be done through the Heroku console and within the web interface. The cleanest and easiest way is the setting of an environment variable. With this out of our way we wan't to enable the maintenance mode as easy as possible.

Using for example set for the Access-Control-Allow-Headers would mean that it doesn't matter if you want to return additional headers from your application, the Apache configuration would always overwrite whatever is given from the application. Make sure to use set or merge purposefully.

Also any other response within our maintenance mode will have the same headers. This is a 100% replacement for the listener and reduced the time Symfony needs for a request (although I doubt that it's measurable). Header merge Access-Control-Allow-Methods "GET,POST,PUT,PATCH,DELETE,OPTIONS". Header merge Access-Control-Allow-Headers "Authorization,Accept-Language,Connection,Content-Type,Content-Length,Host,Origin,User-Agent" Header set Access-Control-Allow-Origin "*" But the application should not be reached in the maintenance mode, so we need to move this into the Apache configuration: # Cors With it, everything returned from Symfony has a header which allows my mobile app to call the API. It was also responsible to add the same headers on any exception. $response->headers->set('Access-Control-Allow-Headers', 'Authorization,Accept-Language,Connection,Content-Type,Content-Length,Host,Origin,User-Agent') $response->headers->set('Access-Control-Allow-Methods', 'GET,POST,PUT,PATCH,DELETE,OPTIONS') $response->headers->set('Access-Control-Allow-Origin', '*') Don't do anything if it's not the master request. Public function onKernelResponse(ResponseEvent $event): void Previously I had the following listener in my application: final class HeaderResponseListener implements EventSubscriberInterface In my case that was everything related to headers, especially Cors headers. Before we can build anything maintenance related, we need to see what we might need to move from our application to a configuration.
#Mamp pro authorization header missing code
The only layer between our application code and the Heroku load balancer is our server configuration. But this would mean that our application is triggered (which might have side effects) and that we need code within our application to handle the maintenance mode. The easiest approach (which is also the one I found all over the internet) would be to simple add a listener to your application (for example Symfony) and return a 503 Service Unavailable response for every request as soon as an environment variable is set.

With those goals in mind, let's see how close we can get.
