Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ trait ApplicationsControllers {

lazy val remoteRender = wire[renderers.DotcomRenderingService]
lazy val siteMapController = wire[SiteMapController]
lazy val dCARAssetsController = wire[DCARAssetsController]
lazy val crosswordPageController = wire[CrosswordPageController]
lazy val crosswordSearchController = wire[CrosswordSearchController]
lazy val crosswordEditionsController = wire[CrosswordEditionsController]
Expand Down
17 changes: 17 additions & 0 deletions applications/app/controllers/DCARAssetsController.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package controllers

import play.api.libs.ws.WSClient
import play.api.mvc.{Action, AnyContent, BaseController, ControllerComponents}
import renderers.DotcomRenderingService

class DCARAssetsController(
wsClient: WSClient,
val controllerComponents: ControllerComponents,
remoteRenderer: renderers.DotcomRenderingService = DotcomRenderingService(),
) extends BaseController {
def renderAsset(): Action[AnyContent] = {
Action.async { implicit request =>
remoteRenderer.getDCARAssets(wsClient, "/assets/rendered-items-assets")
}
}
}
2 changes: 2 additions & 0 deletions applications/conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ GET /assets/*path

GET /_healthcheck controllers.HealthCheck.healthCheck()

GET /dcar-assets/rendered-items-assets controllers.DCARAssetsController.renderAsset()

GET /sitemaps/news.xml controllers.SiteMapController.renderNewsSiteMap()
GET /sitemaps/video.xml controllers.SiteMapController.renderVideoSiteMap()

Expand Down
1 change: 1 addition & 0 deletions common/app/model/Cached.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ object CacheTime {
object FootballMatch extends CacheTime(30)
object Cricket extends CacheTime(60)
object FootballTables extends CacheTime(60)
object DCARAssets extends CacheTime(10)
private def oldArticleCacheTime = if (ShorterSurrogateCacheForOlderArticles.isSwitchedOn) 60 else longCacheTime
def LastDayUpdated = CacheTime(60, Some(oldArticleCacheTime))
def NotRecentlyUpdated = CacheTime(60, Some(oldArticleCacheTime))
Expand Down
22 changes: 22 additions & 0 deletions common/app/renderers/DotcomRenderingService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,28 @@ class DotcomRenderingService extends GuLogging with ResultWithPreconnectPreload
)(implicit request: RequestHeader): Future[Result] =
baseArticleRequest("/AMPArticle", ws, page, blocks, pageType, filterKeyEvents, false, newsletter)

def getDCARAssets(ws: WSClient, path: String)(implicit request: RequestHeader): Future[Result] = {
ws
.url(Configuration.rendering.articleBaseURL + path)
.withRequestTimeout(Configuration.rendering.timeout)
.get()
.map { response =>
response.status match {
case 200 =>
Cached(CacheTime.DCARAssets)(RevalidatableResult.Ok(Html(response.body)))
.withHeaders("X-GU-Dotcomponents" -> "true")
case _ =>
log.error(
s"Request to DCR assets failed: status ${response.status}, path: ${request.path}",
)
NoCache(
InternalServerError("Remote renderer error (500)")
.withHeaders("X-GU-Dotcomponents" -> "true"),
)
}
}
}

def getAppsArticle(
ws: WSClient,
page: PageWithStoryPackage,
Expand Down
Loading