Skip to content

Commit 9be7ddb

Browse files
committed
Update dcar endpoint for assets
1 parent b2185fd commit 9be7ddb

File tree

6 files changed

+39
-29
lines changed

6 files changed

+39
-29
lines changed

applications/app/controllers/ApplicationsControllers.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ trait ApplicationsControllers {
1818

1919
lazy val remoteRender = wire[renderers.DotcomRenderingService]
2020
lazy val siteMapController = wire[SiteMapController]
21+
lazy val dCARAssetsController = wire[DCARAssetsController]
2122
lazy val crosswordPageController = wire[CrosswordPageController]
2223
lazy val crosswordSearchController = wire[CrosswordSearchController]
2324
lazy val crosswordEditionsController = wire[CrosswordEditionsController]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package controllers
2+
3+
import play.api.libs.ws.WSClient
4+
import play.api.mvc.{Action, AnyContent, BaseController, ControllerComponents}
5+
import renderers.DotcomRenderingService
6+
7+
class DCARAssetsController(
8+
wsClient: WSClient,
9+
val controllerComponents: ControllerComponents,
10+
remoteRenderer: renderers.DotcomRenderingService = DotcomRenderingService(),
11+
) extends BaseController {
12+
def renderAsset(): Action[AnyContent] = {
13+
Action.async { implicit request =>
14+
remoteRenderer.getDCARAssets(wsClient, "/assets/rendered-items-assets")
15+
}
16+
}
17+
}

applications/app/controllers/InteractiveController.scala

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@ class InteractiveController(
3434

3535
val capiLookup: CAPILookup = new CAPILookup(contentApiClient)
3636

37-
def renderAsset(): Action[AnyContent] = {
38-
Action.async { implicit request =>
39-
remoteRenderer.getRenderedItemsAsset(wsClient, "/assets/rendered-items-assets.html")
40-
}
41-
}
42-
4337
def renderInteractiveJson(path: String): Action[AnyContent] = renderInteractive(path)
4438
def renderInteractive(path: String): Action[AnyContent] = Action.async { implicit request => renderItem(path) }
4539

applications/conf/routes

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# Routes
22
# This file defines all application routes (Higher priority routes first)
33
# ~~~~
4-
GET /app-assets/rendered-items-assets controllers.InteractiveController.renderAsset()
4+
55
# For dev machines
66
GET /assets/*path dev.DevAssetsController.at(path)
77

88
GET /_healthcheck controllers.HealthCheck.healthCheck()
99

10+
GET /dcar-assets/rendered-items-assets controllers.DCARAssetsController.renderAsset()
11+
1012
GET /sitemaps/news.xml controllers.SiteMapController.renderNewsSiteMap()
1113
GET /sitemaps/video.xml controllers.SiteMapController.renderVideoSiteMap()
1214

common/app/model/Cached.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ object CacheTime {
3232
object FootballMatch extends CacheTime(30)
3333
object Cricket extends CacheTime(60)
3434
object FootballTables extends CacheTime(60)
35+
object DCARAssets extends CacheTime(10)
3536
private def oldArticleCacheTime = if (ShorterSurrogateCacheForOlderArticles.isSwitchedOn) 60 else longCacheTime
3637
def LastDayUpdated = CacheTime(60, Some(oldArticleCacheTime))
3738
def NotRecentlyUpdated = CacheTime(60, Some(oldArticleCacheTime))

common/app/renderers/DotcomRenderingService.scala

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -157,31 +157,26 @@ class DotcomRenderingService extends GuLogging with ResultWithPreconnectPreload
157157
)(implicit request: RequestHeader): Future[Result] =
158158
baseArticleRequest("/AMPArticle", ws, page, blocks, pageType, filterKeyEvents, false, newsletter)
159159

160-
def getRenderedItemsAsset(ws: WSClient, path: String)(implicit request: RequestHeader): Future[Result] = {
161-
val dcrRequest = ws
160+
def getDCARAssets(ws: WSClient, path: String)(implicit request: RequestHeader): Future[Result] = {
161+
ws
162162
.url(Configuration.rendering.articleBaseURL + path)
163163
.withRequestTimeout(Configuration.rendering.timeout)
164-
.addHttpHeaders("Content-Type" -> "application/json")
165-
166-
def handler(response: WSResponse): Result = {
167-
response.status match {
168-
case 200 =>
169-
Cached(CacheTime.Default)(RevalidatableResult.Ok(Html(response.body)))
170-
.withHeaders("X-GU-Dotcomponents" -> "true")
171-
case _ =>
172-
log.error(
173-
s"Request to DCR asset failed: status ${response.status}, path: ${request.path}, body: ${response.body}",
174-
)
175-
NoCache(
176-
InternalServerError("Remote renderer error (500)")
177-
.withHeaders("X-GU-Dotcomponents" -> "true"),
178-
)
164+
.get()
165+
.map { response =>
166+
response.status match {
167+
case 200 =>
168+
Cached(CacheTime.DCARAssets)(RevalidatableResult.Ok(Html(response.body)))
169+
.withHeaders("X-GU-Dotcomponents" -> "true")
170+
case _ =>
171+
log.error(
172+
s"Request to DCR assets failed: status ${response.status}, path: ${request.path}",
173+
)
174+
NoCache(
175+
InternalServerError("Remote renderer error (500)")
176+
.withHeaders("X-GU-Dotcomponents" -> "true"),
177+
)
178+
}
179179
}
180-
}
181-
182-
val response = dcrRequest.get()
183-
184-
response.map(handler)
185180
}
186181

187182
def getAppsArticle(

0 commit comments

Comments
 (0)