Skip to content

Commit

Permalink
Merge branch 'latest' into WSTEAMA-303-message-banner-tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
karinathomasbbc authored Jan 22, 2024
2 parents 749d761 + 6fe8868 commit 2aa1ba0
Show file tree
Hide file tree
Showing 14 changed files with 66 additions and 36 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/simorgh-local-server-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ jobs:
env:
CI: true
LOG_LEVEL: 'error'
BFF_PATH: 'https://web-cdn.test.api.bbci.co.uk/fd/simorgh-bff'
LIGHTHOUSE_BUILD: true

steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -54,7 +56,7 @@ jobs:

- name: Start Simorgh Server - Next.JS App
working-directory: ./ws-nextjs-app
run: nohup node build/standalone/server.js > /dev/null 2>&1 &
run: PORT=7081 nohup node build/standalone/ws-nextjs-app/server.js &

- name: Run AMP Validator
run: yarn amp:validate
Expand Down
7 changes: 5 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@
"configurations": [
{
"type": "node",
"runtimeVersion": "16",
"runtimeVersion": "18",
"request": "launch",
"name": "Debug Express App",
"program": "${workspaceFolder}/node_modules/webpack/bin/webpack.js",
"args": [
"--watch", "--progress", "--env" , "config='server'"
],
"env" : { "NODE_ENV" : "development" }
"env" : { "NODE_ENV" : "development" },
"skipFiles": [
"${workspaceFolder}/node_modules/**/*",
]
}
]
}
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
"dotenv": "16.0.3",
"express": "4.18.2",
"express-static-gzip": "2.1.7",
"helmet": "4.6.0",
"helmet": "7.1.0",
"helmet-csp": "3.4.0",
"intersection-observer": "0.12.2",
"isarray": "2.0.5",
Expand Down
3 changes: 2 additions & 1 deletion scripts/lighthouseRun.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash
set -e

npx -p lighthouse@11.3.0 lighthouse http://localhost:7080/news/articles/cn7k01xp8kxo --chrome-flags="--no-sandbox --headless --disable-gpu" --output json --output html --output-path simorgh --config-path scripts/lighthouseConfig.js && node scripts/lighthouseBudget.js run
npx -p lighthouse@11.3.0 lighthouse http://localhost:7080/kyrgyz --chrome-flags="--no-sandbox --headless --disable-gpu" --output json --output html --output-path simorgh --config-path scripts/lighthouseConfig.js && node scripts/lighthouseBudget.js run
npx -p lighthouse@11.3.0 lighthouse http://localhost:7081/pidgin/live/c7p765ynk9qt --chrome-flags="--no-sandbox --headless --disable-gpu" --output json --output html --output-path simorgh --config-path scripts/lighthouseConfig.js && node scripts/lighthouseBudget.js run
npx -p lighthouse@11.3.0 lighthouse http://localhost:7081/pidgin/live/c07zr0zwjnnt --chrome-flags="--no-sandbox --headless --disable-gpu" --output json --output html --output-path simorgh --config-path scripts/lighthouseConfig.js && node scripts/lighthouseBudget.js run
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const nodeLogger = require('#lib/logger.node');
const logger = nodeLogger(__filename);

const handleMissingType = (block, json, assetType) =>
logger.info(UNSUPPORTED_BLOCK_TYPE, {
logger.debug(UNSUPPORTED_BLOCK_TYPE, {
url: json.metadata.locators.assetUri,
type: block.type,
assetType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ describe('convertToOptimoBlocks', () => {
});
});

it('should log info if block type is unsupported', async () => {
it('should log debug if block type is unsupported', async () => {
const url = '/service/path/to/asset';
const type = 'unsupported-type-name-here';
const assetType = MEDIA_ASSET_PAGE;
Expand All @@ -312,7 +312,7 @@ describe('convertToOptimoBlocks', () => {
};

await convertToOptimoBlocks(input);
expect(loggerMock.info).toHaveBeenCalledWith(UNSUPPORTED_BLOCK_TYPE, {
expect(loggerMock.debug).toHaveBeenCalledWith(UNSUPPORTED_BLOCK_TYPE, {
url,
type,
assetType,
Expand Down
39 changes: 24 additions & 15 deletions src/app/routes/utils/certsRequired/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,39 @@ jest.mock('../getEnvironment', () =>

describe('certsRequired', () => {
const originalIntegrationTestBuild = process.env.INTEGRATION_TEST_BUILD;
const originaLighthouseTestBuild = process.env.LIGHTHOUSE_TEST_BUILD;

afterEach(() => {
process.env.INTEGRATION_TEST_BUILD = originalIntegrationTestBuild;
process.env.LIGHTHOUSE_TEST_BUILD = originaLighthouseTestBuild;
});

it.each`
url | environment | integrationTestBuild | expected
${'/mundo'} | ${'local'} | ${undefined} | ${false}
${'/mundo'} | ${'local'} | ${'true'} | ${false}
${'/mundo'} | ${'local'} | ${true} | ${false}
${'/mundo'} | ${undefined} | ${undefined} | ${false}
${'/mundo'} | ${undefined} | ${'true'} | ${false}
${'/mundo'} | ${undefined} | ${true} | ${false}
${'/mundo'} | ${'test'} | ${undefined} | ${true}
${'/mundo'} | ${'test'} | ${'true'} | ${false}
${'/mundo'} | ${'test'} | ${true} | ${false}
${'/mundo'} | ${'live'} | ${undefined} | ${true}
${'/mundo'} | ${'live'} | ${'true'} | ${false}
${'/mundo'} | ${'live'} | ${true} | ${false}
url | environment | integrationTestBuild | lighthouseTestBuild | expected
${'/mundo'} | ${'local'} | ${undefined} | ${undefined} | ${false}
${'/mundo'} | ${'local'} | ${'true'} | ${'true'} | ${false}
${'/mundo'} | ${'local'} | ${true} | ${true} | ${false}
${'/mundo'} | ${undefined} | ${undefined} | ${undefined} | ${false}
${'/mundo'} | ${undefined} | ${'true'} | ${'true'} | ${false}
${'/mundo'} | ${undefined} | ${true} | ${true} | ${false}
${'/mundo'} | ${'test'} | ${undefined} | ${undefined} | ${true}
${'/mundo'} | ${'test'} | ${'true'} | ${'true'} | ${false}
${'/mundo'} | ${'test'} | ${true} | ${true} | ${false}
${'/mundo'} | ${'live'} | ${undefined} | ${undefined} | ${true}
${'/mundo'} | ${'live'} | ${'true'} | ${'true'} | ${false}
${'/mundo'} | ${'live'} | ${true} | ${true} | ${false}
`(
'returns $expected when environment is $environment, integrationTestBuild is $integrationTestBuild and url is $url',
({ url, environment, integrationTestBuild, expected }) => {
'returns $expected when environment is $environment, integrationTestBuild is $integrationTestBuild, lighthouseTestBuild is $lighthouseTestBuild and url is $url',
({
url,
environment,
integrationTestBuild,
lighthouseTestBuild,
expected,
}) => {
(getEnvironment as jest.Mock).mockImplementationOnce(() => environment);
process.env.INTEGRATION_TEST_BUILD = integrationTestBuild;
process.env.LIGHTHOUSE_TEST_BUILD = lighthouseTestBuild;
expect(certsRequired(url)).toBe(expected);
},
);
Expand Down
6 changes: 5 additions & 1 deletion src/app/routes/utils/certsRequired/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@ import getEnvironment from '../getEnvironment';
export default (pathname: string) => {
const environment = getEnvironment(pathname);
const isLocal = environment === 'local' || !environment;
return !isLocal && process.env.INTEGRATION_TEST_BUILD !== 'true';
return (
!isLocal &&
process.env.INTEGRATION_TEST_BUILD !== 'true' &&
process.env.LIGHTHOUSE_BUILD !== 'true'
);
};
5 changes: 4 additions & 1 deletion src/server/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,12 @@ server
.use(compression())
.use(
helmet({
expectCt: false,
frameguard: { action: 'deny' },
contentSecurityPolicy: false,
crossOriginEmbedderPolicy: false,
crossOriginOpenerPolicy: false,
crossOriginResourcePolicy: false,
originAgentCluster: false,
}),
)
.use(logResponseTime)
Expand Down
11 changes: 8 additions & 3 deletions ws-nextjs-app/pages/[service]/live/[id]/[[...variant]].page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import getToggles from '#app/lib/utilities/getToggles/withCache';
import { LIVE_PAGE } from '#app/routes/utils/pageTypes';
import nodeLogger from '#lib/logger.node';
import logResponseTime from '#server/utilities/logResponseTime';
import isAppPath from '#app/routes/utils/isAppPath';

import {
ROUTING_INFORMATION,
Expand Down Expand Up @@ -41,7 +42,7 @@ const getPageData = async ({
page,
service,
variant,
rendererEnv,
rendererEnv = 'test',
}: PageDataParams) => {
const pathname = `${id}${rendererEnv ? `?renderer_env=${rendererEnv}` : ''}`;
const livePageUrl = constructPageFetchUrl({
Expand Down Expand Up @@ -107,17 +108,20 @@ export const getServerSideProps: GetServerSideProps = async context => {
id,
service,
variant,
// renderer_env: rendererEnv,
renderer_env: rendererEnv,
page = '1',
} = context.query as PageDataParams;

const { headers: reqHeaders } = context.req;

const isApp = isAppPath(context.resolvedUrl);

if (!isValidPageNumber(page)) {
context.res.statusCode = 404;
return {
props: {
bbcOrigin: reqHeaders['bbc-origin'] || null,
isApp,
isNextJs: true,
service,
status: 404,
Expand All @@ -142,7 +146,7 @@ export const getServerSideProps: GetServerSideProps = async context => {
page,
service,
variant,
rendererEnv: 'test', // TODO: remove hardcoding
rendererEnv,
});

let routingInfoLogger = logger.debug;
Expand All @@ -162,6 +166,7 @@ export const getServerSideProps: GetServerSideProps = async context => {
bbcOrigin: reqHeaders['bbc-origin'] || null,
error: data?.error || null,
id,
isApp,
isAmp: false,
isNextJs: true,
page: page || null,
Expand Down
9 changes: 6 additions & 3 deletions ws-nextjs-app/pages/_document.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@ import Document, {
} from 'next/document';
import * as React from 'react';
import { Helmet, HelmetData } from 'react-helmet';
import isAppPath from '#app/routes/utils/isAppPath';

type DocProps = { helmet: HelmetData };
type DocProps = { helmet: HelmetData; isApp: boolean };

export default class AppDocument extends Document<DocProps> {
static async getInitialProps(ctx: DocumentContext) {
const initialProps = await Document.getInitialProps(ctx);
const isApp = isAppPath(ctx.asPath || '');

return { ...initialProps, helmet: Helmet.renderStatic() };
return { ...initialProps, helmet: Helmet.renderStatic(), isApp };
}

render() {
const { helmet } = this.props;
const { helmet, isApp } = this.props;

const htmlAttrs = helmet.htmlAttributes.toComponent();
const meta = helmet.meta.toComponent();
Expand All @@ -29,6 +31,7 @@ export default class AppDocument extends Document<DocProps> {
return (
<Html {...htmlAttrs}>
<Head>
{isApp && <meta name="robots" content="noindex" />}
{meta}
{title}
{helmetLinkTags}
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13321,10 +13321,10 @@ __metadata:
languageName: node
linkType: hard

"helmet@npm:4.6.0":
version: 4.6.0
resolution: "helmet@npm:4.6.0"
checksum: 139ad678d1cab207b043c206f50f6744eff2ef1f463e4626d36718b45b337485c77d10260ef9d89d292fa678da5153d86b08172b3b365cc8e680241015ed3a49
"helmet@npm:7.1.0":
version: 7.1.0
resolution: "helmet@npm:7.1.0"
checksum: 16aaa0df997eaa18821e71389bc9ceffeeaa935df98427ede2bb006065f7e02bb1941caabea16d5a93a791cb3fe7d8a760266bc57b3b9ca5dd7da17ea84244b8
languageName: node
linkType: hard

Expand Down Expand Up @@ -20889,7 +20889,7 @@ __metadata:
express-static-gzip: 2.1.7
fetch-mock: 9.11.0
glob: 8.0.3
helmet: 4.6.0
helmet: 7.1.0
helmet-csp: 3.4.0
history: 4.10.1
husky: 8.0.3
Expand Down

0 comments on commit 2aa1ba0

Please sign in to comment.