LoginSignup
1
1

More than 5 years have passed since last update.

PlayFramework インターセプト

Posted at

リクエストのインターセプト

GolobalSettignsを継承したクラスを使用し、アプリケーション起動時や終了時に処理をいれることができます。
今回はリクエスト時に処理をフックする方法をご紹介します。

サンプル

global.scalaファイルを作成し、下記のように記述します。

sample
import play.api._
import play.api.mvc._
import play.api.mvc.Results._

object Global extends GlobalSettings {

  override def onRouteRequest(request: RequestHeader): Option[Handler] = {
     println("リクエストの確認:")
     println("executed before every request:" + request.toString)
     super.onRouteRequest(request)
  }
}

onRouteRequestをオーバーライドすることで、リクエストをフックすることができます。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1