File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed
dotcom-rendering/src/server Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change 1+ import type { Handler } from 'express' ;
2+ import { validateAsFEArticle } from '../../../src/model/validate' ;
3+
4+ export const addQueryParamsToABTests : Handler = async ( req , res , next ) => {
5+ try {
6+ const frontendData = validateAsFEArticle ( req . body ) ;
7+
8+ const { config } = frontendData ;
9+
10+ const queryParamsAb = req . query ;
11+
12+ const filteredQuery : Record < string , string > = { } ;
13+ for ( const [ key , value ] of Object . entries ( queryParamsAb ) ) {
14+ if ( typeof value == 'string' && key . startsWith ( 'ab-' ) ) {
15+ const testId = key . replace ( / ^ a b - / , '' ) ;
16+ filteredQuery [ testId ] = value ;
17+ }
18+ }
19+
20+ config . serverSideABTests = {
21+ ...config . serverSideABTests ,
22+ ...filteredQuery ,
23+ } ;
24+ req . body = frontendData ;
25+ } catch ( error ) {
26+ return next ( ) ;
27+ }
28+ next ( ) ;
29+ } ;
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ import {
2020 handleFootballMatchPage ,
2121 handleFootballTablesPage ,
2222} from './handler.sportDataPage.web' ;
23+ import { addQueryParamsToABTests } from './lib/add-queryparams-to-abtests' ;
2324import { getContentFromURLMiddleware } from './lib/get-content-from-url' ;
2425
2526/** article URLs contain a part that looks like “2022/nov/25” */
@@ -89,6 +90,7 @@ const renderer = Router();
8990// populates req.body with the content data from a production
9091// URL if req.params.url is present
9192renderer . use ( getContentFromURLMiddleware ) ;
93+ renderer . use ( addQueryParamsToABTests ) ;
9294renderer . get ( '/Article/*url' , handleArticle ) ;
9395renderer . get ( '/Interactive/*url' , handleInteractive ) ;
9496renderer . get ( '/Blocks/*url' , handleBlocks ) ;
You can’t perform that action at this time.
0 commit comments