Skip to content

Conversation

arelra
Copy link
Member

@arelra arelra commented Aug 19, 2025

What does this change?

We wish to remove the GET endpoints from the prod server as they aren't used in production and we don't use them for manual testing.

Background

Prod

In production Frontend will POST a JSON payload to DCR to render.
In production no GET endpoints are used.

Dev

The dev server configures both GET and POST handlers for each endpoint.
The GET endpoints allow us to conveniently load any page in a browser with a GET request such as:

http://localhost:3030/Article/https://www.theguardian.com/world/2025/aug/19/the-big-church-move-sweden-kiruna-kyrka

The GET endpoints will fetch the required payload from Frontend via the middleware getContentFromURLMiddleware and pass on to the normal rendering flow to render the page.

renderer.use(getContentFromURLMiddleware);
renderer.get('/Article/*url', handleArticle);
renderer.get('/AMPArticle/*url', handleAMPArticle);
renderer.get('/Interactive/*url', handleInteractive);
renderer.get('/AMPInteractive/*url', handleAMPArticle);
renderer.get('/Blocks/*url', handleBlocks);
renderer.get('/Front/*url', handleFront);
renderer.get('/TagPage/*url', handleTagPage);
renderer.get('/EmailNewsletters/*url', handleAllEditorialNewslettersPage);
renderer.get('/AppsArticle/*url', handleAppsArticle);
renderer.get('/AppsInteractive/*url', handleAppsInteractive);
renderer.get('/AppsBlocks/*url', handleAppsBlocks);
renderer.get('/EditionsCrossword/*url', handleEditionsCrossword);
renderer.get('/FootballMatchListPage/*url', handleFootballMatchListPage);
renderer.get('/FootballTablesPage/*url', handleFootballTablesPage);
renderer.get('/CricketMatchPage/*url', handleCricketMatchPage);
renderer.get('/FootballMatchSummaryPage/*url', handleFootballMatchPage);
// POST routes for running frontend locally
renderer.post('/Article', handleArticle);
renderer.post('/AMPArticle', handleAMPArticle);
renderer.post('/Interactive', handleInteractive);
renderer.post('/AMPInteractive', handleAMPArticle);
renderer.post('/Blocks', handleBlocks);
renderer.post('/Front', handleFront);
renderer.post('/TagPage', handleTagPage);
renderer.post('/EmailNewsletters', handleAllEditorialNewslettersPage);
renderer.post('/AppsArticle', handleAppsArticle);
renderer.post('/AppsInteractive', handleAppsInteractive);
renderer.post('/AppsBlocks', handleAppsBlocks);
renderer.post('/EditionsCrossword', handleEditionsCrossword);
renderer.post('/FootballMatchListPage', handleFootballMatchListPage);
renderer.post('/FootballTablesPage', handleFootballTablesPage);
renderer.post('/CricketMatchPage', handleCricketMatchPage);
renderer.post('/FootballMatchSummaryPage', handleFootballMatchPage);

export const getContentFromURLMiddleware: Handler = async (req, res, next) => {
if (req.path === '/EditionsCrossword') {
try {
const url = new URL(
'https://www.theguardian.com/crosswords/digital-edition',
);
const content = await getContentFromURL(url, req.headers);
req.body = content;
next();
} catch (error) {
console.error(error);
next(error);
}
} else {
const sourceURL = parseURL(req.originalUrl);
if (sourceURL) {
if (
req.path.startsWith('/AMP') &&
sourceURL.hostname === 'www.theguardian.com'
) {
res.redirect(
req.path.replace(
'www.theguardian.com',
'amp.theguardian.com',
),
);
}
try {
req.body = await getContentFromURL(sourceURL, req.headers);
} catch (error) {
console.error(error);
next(error);
}
}
next();
}

Playwright

The Playwright tests use:

  • the dev server for local testing
  • the prod server in CI via the container we spin up in production mode

The Playwright tests (and previously Cypress) relied on the GET endpoints which offloaded the responsibility of fetching the Frontend JSON payload to DCR.

In order to remove the GET endpoints from the prod server, the Playwright tests now need to use the POST endpoints instead which are available on both the dev and prod servers.

This requires the Playwright utility load-page.ts to fetch the required content payload from Frontend itself and then POST to DCR.

Why?

Reduce prod server surface area

Copy link

github-actions bot commented Aug 19, 2025

Copy link

github-actions bot commented Aug 19, 2025

@arelra arelra added the run_chromatic Runs chromatic when label is applied label Aug 19, 2025
@github-actions github-actions bot removed the run_chromatic Runs chromatic when label is applied label Aug 19, 2025
arelra added 8 commits August 20, 2025 12:55
Ensures correct value is set for Edition from the forceful setting of the GU_EDITION cookie.
- rename article to feFixture in load-page
- undo playwright.config changes used for testing
- set local workers to 2 to improve stability
@arelra arelra force-pushed the ravi/playwright-uses-post-endpoints branch from 685a410 to ff579ba Compare August 20, 2025 11:56
@arelra arelra added the run_chromatic Runs chromatic when label is applied label Aug 20, 2025
@arelra arelra marked this pull request as ready for review August 20, 2025 12:00
@arelra arelra requested a review from a team as a code owner August 20, 2025 12:00
@github-actions github-actions bot removed the run_chromatic Runs chromatic when label is applied label Aug 20, 2025
@arelra arelra added the run_chromatic Runs chromatic when label is applied label Aug 20, 2025
@github-actions github-actions bot removed the run_chromatic Runs chromatic when label is applied label Aug 20, 2025
@arelra arelra merged commit e2a4866 into main Aug 21, 2025
31 checks passed
@arelra arelra deleted the ravi/playwright-uses-post-endpoints branch August 21, 2025 14:02
@gu-prout
Copy link

gu-prout bot commented Aug 21, 2025

Seen on PROD (merged by @arelra 8 minutes and 44 seconds ago) Please check your changes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants