Kat
Kat

Reputation: 4695

Maintenance mode for the Play Framework

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?

Upvotes: 3

Views: 540

Answers (1)

acjay
acjay

Reputation: 36571

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.

Upvotes: 4

Related Questions