Is there any way to enable the display of a static HTML page to explain that a site is in maintenance during times such as when the Play Framework is compiling new code?
I can see how we could manually create a maintenance page for things such as while a long database or file change is undergoing (during which the application may be in an inconsistent state), but is there any built-in approach for the Play Framework?
I know that some other major server software like Nginx have a way to display a static resource here. Since the Play Framework is also the server software, does it have an equivalent?
Sure. Your best bet is to use request interceptors. This is using a request filter, lightly adapted from those docs:
import play.api.Logger
import play.api.mvc._
object MaintenanceModeFilter extends Filter {
def apply(next: (RequestHeader) => Future[Result])(request: RequestHeader): Future[Result] = {
if (/* check for trigger */) {
Logger.info("Sending maintenance mode response")
Ok(/* your maintenance page */)
} else {
next(request)
}
}
}
object Global extends WithFilters(AccessLoggingFilter)
You could probably make it work with onRouteRequest, also mentioned in those docs, if you prefer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With