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
18 changes: 18 additions & 0 deletions dotcom-rendering/src/server/dev-index.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,24 @@ <h2>Pages</h2>
>🏏 Cricket Match Page</a
>
</li>
<li>
<a
href="/HostedContent/https://www.theguardian.com/advertiser-content/bloomberg-philanthropies/vision-for-a-healthy-future"
>💷 Hosted Article</a
>
</li>
<li>
<a
href="/HostedContent/https://www.theguardian.com/advertiser-content/gsk-oncology/unlocking-the-future-of-cancer-care"
>💰 Hosted Video</a
>
</li>
<li>
<a
href="/HostedContent/https://www.theguardian.com/advertiser-content/canary-islands-rugby/the-spanish-rugby-sevens-team"
>💸 Hosted Gallery</a
>
</li>
</ul>
<form name="url-form">
<input
Expand Down
18 changes: 18 additions & 0 deletions dotcom-rendering/src/server/handler.hostedContent.web.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { RequestHandler } from 'express';
import { validateAsFEHostedContent } from '../model/validate';
import { enhanceHostedContentType } from '../types/hostedContent';
import { makePrefetchHeader } from './lib/header';
import { recordTypeAndPlatform } from './lib/logging-store';
import { renderHtml } from './render.hostedContent.web';

export const handleHostedContent: RequestHandler = ({ body }, res) => {
recordTypeAndPlatform('article', 'web');

const frontendData = validateAsFEHostedContent(body);
const hostedContent = enhanceHostedContentType(frontendData);
const { html, prefetchScripts } = renderHtml({
hostedContent,
});

res.status(200).set('Link', makePrefetchHeader(prefetchScripts)).send(html);
};
56 changes: 56 additions & 0 deletions dotcom-rendering/src/server/render.hostedContent.web.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { isString } from '@guardian/libs';
import { HostedArticleLayout } from '../layouts/HostedArticleLayout';
import { HostedGalleryLayout } from '../layouts/HostedGalleryLayout';
import { getModulesBuild, getPathFromManifest } from '../lib/assets';
import { renderToStringWithEmotion } from '../lib/emotion';
import { polyfillIO } from '../lib/polyfill.io';
import type { HostedContent } from '../types/hostedContent';
import { htmlPageTemplate } from './htmlPageTemplate';

type Props = {
hostedContent: HostedContent;
};

export const renderHtml = ({ hostedContent }: Props) => {
const { type, frontendData } = hostedContent;

const title = `Advertiser content hosted by the Guardian: ${frontendData.title} | The Guardian`;

const HostedLayout =
type === 'gallery' ? HostedGalleryLayout : HostedArticleLayout;
const renderingTarget = 'Web';

const { html, extractedCss } = renderToStringWithEmotion(
<HostedLayout renderingTarget={renderingTarget} />,
);

// We don't send A/B tests or switches from frontend yet- do we need to?
const build = getModulesBuild({
tests: {},
switches: {},
});

const prefetchScripts = [
polyfillIO,
getPathFromManifest(build, 'frameworks.js'),
getPathFromManifest(build, 'index.js'),
].filter(isString);

// We currently don't send any of the data required for page config or window.guardian setup from frontend
const pageHtml = htmlPageTemplate({
scriptTags: [],
css: extractedCss,
html,
title,
description: frontendData.standfirst,
// @ts-expect-error no config data
guardian: {},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the createGuardian function is it best to populate the HostedContent["frontendData"] object with the Config object, as most of the fields like sentryHost, frontendAssetsFullURL, googletagUrl are needed for the pages? Or would you recommend we wait for the full spec of the page to be released before attempting to populate the window.guardian object?

canonicalUrl: '',
renderingTarget: 'Web',
// @ts-expect-error no config data
config: {},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be completed (at least partially) like so:

config: {
	renderingTarget: 'Web',
	assetOrigin: ASSET_ORIGIN,
	darkModeAvailable: ... // if we can feed in the a/b test switches then we can populate this
}

weAreHiring: false,
});

return { html: pageHtml, prefetchScripts };
};
4 changes: 4 additions & 0 deletions dotcom-rendering/src/server/server.dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import { handleAppsAssets } from './handler.assets.apps';
import { handleEditionsCrossword } from './handler.editionsCrossword';
import { handleFront, handleTagPage } from './handler.front.web';
import { handleHostedContent } from './handler.hostedContent.web';
import {
handleCricketMatchPage,
handleFootballMatchListPage,
Expand Down Expand Up @@ -106,6 +107,8 @@ renderer.get('/FootballMatchListPage/*url', handleFootballMatchListPage);
renderer.get('/FootballTablesPage/*url', handleFootballTablesPage);
renderer.get('/CricketMatchPage/*url', handleCricketMatchPage);
renderer.get('/FootballMatchSummaryPage/*url', handleFootballMatchPage);
renderer.get('/HostedContent/*url', handleHostedContent);

// POST routes for running frontend locally
renderer.post('/Article', handleArticle);
renderer.post('/Interactive', handleInteractive);
Expand All @@ -121,6 +124,7 @@ renderer.post('/FootballMatchListPage', handleFootballMatchListPage);
renderer.post('/FootballTablesPage', handleFootballTablesPage);
renderer.post('/CricketMatchPage', handleCricketMatchPage);
renderer.post('/FootballMatchSummaryPage', handleFootballMatchPage);
renderer.post('/HostedContent', handleHostedContent);

renderer.get('/assets/rendered-items-assets', handleAppsAssets);

Expand Down
2 changes: 2 additions & 0 deletions dotcom-rendering/src/server/server.prod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
import { handleAppsAssets } from './handler.assets.apps';
import { handleEditionsCrossword } from './handler.editionsCrossword';
import { handleFront, handleTagPage } from './handler.front.web';
import { handleHostedContent } from './handler.hostedContent.web';
import {
handleCricketMatchPage,
handleFootballMatchListPage,
Expand Down Expand Up @@ -75,6 +76,7 @@ export const prodServer = (): void => {
logRenderTime,
handleFootballMatchPage,
);
app.post('/HostedContent', logRenderTime, handleHostedContent);

app.post(
'/EmailNewsletters',
Expand Down
Loading