private def injectClientCodeIntoPageBody()

in newswires/app/controllers/ViteController.scala [51:85]


  private def injectClientCodeIntoPageBody(
      html: String
  )(implicit request: Request[AnyContent]): String = {
    def injectCsrf[A](
        body: String
    )(implicit request: Request[A]): String = {
      val csrf = CSRF.getToken

      body
        .replaceAll("@csrf\\.name", csrf.name)
        .replaceAll("@csrf\\.value", csrf.value)
    }

    def injectClientConfig(body: String): String = {
      val config =
        views.html.fragments.clientConfig(
          ClientConfig(
            FeatureSwitchProvider.clientSideSwitchStates,
            stage = configuration.get[String]("stage")
          )
        )

      body.replace(
        "</head>",
        s"""
           | <!-- Client config added at runtime by ViteController. -->
           |$config
           |</head>""".stripMargin
      )
    }

    val withInjectedCsrf = injectCsrf(html)(request)
    injectClientConfig(withInjectedCsrf)

  }