I want to implement a sort of maintenance mode for a site that I’m building on Slim/Twig. I want to be able to change a flag and have the site become offline for everyone except the people in our office.
I have set an environment variable called SITE_OFFLINE which can be changed in the application (running in Docker on local and Elastic Beanstalk in production) and have created a small middleware to check that setting as follows:
$app->add(function (Request $request, Response $response, callable $next) : Response
{
if ($this->get('settings')['offline']) {
return $response->withStatus(503)->withHeader('Retry-After', 3600); // Retry in an hour please :)
}
return $next($request, $response);
});
So far, so good. I just need to add an IP check to determine that we’re coming from our office and to not appear offline.
The problem that I’ve got is that I don’t know how to display the offline message. I’m using Twig for the rest of the site, but I just wanted to import a static HTML page instead for the sake of the offline message. Presumably I need something like:
return $response->withStatus(503)->withHeader('Retry-After', 3600)->withBody(
// What goes here?
);
Any guidance? I didn’t want to run it through Twig if I could afford it, and I definitely don’t want to redirect; it should display the offline message on the same URL.
Wow, it’s actually that simple? I mean, I wasn’t wanting to use Twig for this page (would’ve been quite happy to just give it a simple, static HTML page for the sake of simplicity) but this does the job really easily. Yeah, happy with that, thanks @RikuS