Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 0 additions & 1 deletion src/app/lib/config/services/archive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export const service: DefaultServiceConfig = {
publishingPrinciples: null,
isTrustProjectParticipant: false,
script: latin,
swPath: '/articles/sw.js',
homePageTitle: 'Home',
showAdPlaceholder: false,
showRelatedTopics: true,
Expand Down
1 change: 0 additions & 1 deletion src/app/lib/config/services/scotland.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export const service: DefaultServiceConfig = {
publishingPrinciples: null,
isTrustProjectParticipant: false,
script: latin,
swPath: '/articles/sw.js',
homePageTitle: 'Home',
passportHomes: ['BBCScotland'],
showAdPlaceholder: false,
Expand Down
11 changes: 5 additions & 6 deletions src/app/routes/utils/regex/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,16 @@ describe('homePageDataPath', () => {
});

describe('articleSwPath', () => {
const validRoutes = [
'/news/articles/sw.js',
'/persian/articles/sw.js',
'/cymrufyw/erthyglau/sw.js',
];
const validRoutes = ['/gahuza/articles/sw.js', '/persian/articles/sw.js'];
shouldMatchValidRoutes(validRoutes, articleSwPath);

const invalidRoutes = [
'/news/sw.js',
'/news/articles/sw.js',
Copy link
Contributor

Choose a reason for hiding this comment

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

I am wondering whether to add examples of all sw paths which are now invalid, for all Public Services? Especially if we have excluded them explictly from the regex.

So this would be:

  • /sport/articles/sw.js
  • /newsround/articles/sw.js
  • /archive/articles/sw.js
  • /scotland/articles/sw.js
  • /naidheachdan/sgeulachdan/sw.js

Copy link
Member Author

@elvinasv elvinasv Mar 26, 2025

Choose a reason for hiding this comment

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

Good point, updated

'/persian/articles/sw',
'/news/trad/sw.js',
'/cymrufyw/sw.js',
'/cymrufyw/erthyglau/sw.js',
];
shouldNotMatchInvalidRoutes(invalidRoutes, articleSwPath);
});
Expand Down Expand Up @@ -166,10 +164,11 @@ describe('articleManifestPath', () => {
});

describe('homePageSwPath', () => {
const validRoutes = ['/news/sw.js', '/persian/sw.js'];
const validRoutes = ['/gahuza/sw.js', '/persian/sw.js'];
shouldMatchValidRoutes(validRoutes, homePageSwPath);

const invalidRoutes = [
'/news/sw.js',
'/news/articles/sw.js',
'/persian/sw',
'/persian/simp/sw.js',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

exports[`regex utils snapshots should create expected regex from getAfricaEyeTVPageRegex 1`] = `"/worldservice/tv/africa_eye/:episodeId([a-z0-9]+)?:lite(.lite)?"`;

exports[`regex utils snapshots should create expected regex from getArticleManifestRegex 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|azeri|bengali|burmese|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|nepali|pashto|persian|pidgin|portuguese|punjabi|russian|scotland|serbian|sinhala|somali|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|ws|yoruba|zhongwen)/:local(articles|erthyglau|sgeulachdan)/manifest.json"`;
exports[`regex utils snapshots should create expected regex from getArticleManifestRegex 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|azeri|bengali|burmese|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|nepali|pashto|persian|pidgin|portuguese|punjabi|russian|serbian|sinhala|somali|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|ws|yoruba|zhongwen)/:local(articles|erthyglau|sgeulachdan)/manifest.json"`;

exports[`regex utils snapshots should create expected regex from getArticleRegex 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|archive|azeri|bengali|burmese|cymrufyw|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|naidheachdan|nepali|news|newsround|pashto|persian|pidgin|portuguese|punjabi|russian|scotland|serbian|sinhala|somali|sport|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|ws|yoruba|zhongwen)?:discipline(/[a-z0-9-_]{1,})?/:local(articles|erthyglau|sgeulachdan)/:id(c[a-zA-Z0-9]{10}o):variant(/simp|/trad|/cyr|/lat)?:nonCanonicalArticleRenderPlatform(.amp|.app|.lite)?"`;

exports[`regex utils snapshots should create expected regex from getArticleSwRegex 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|archive|azeri|bengali|burmese|cymrufyw|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|naidheachdan|nepali|news|newsround|pashto|persian|pidgin|portuguese|punjabi|russian|scotland|serbian|sinhala|somali|sport|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|ws|yoruba|zhongwen)/:local(articles|erthyglau|sgeulachdan)/sw.js"`;
exports[`regex utils snapshots should create expected regex from getArticleSwRegex 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|azeri|bengali|burmese|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|nepali|pashto|persian|pidgin|portuguese|punjabi|russian|serbian|sinhala|somali|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|ws|yoruba|zhongwen)/:local(articles|erthyglau|sgeulachdan)/sw.js"`;

exports[`regex utils snapshots should create expected regex from getCpsAssetRegex 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|archive|azeri|bengali|burmese|cymrufyw|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|naidheachdan|nepali|news|newsround|pashto|persian|pidgin|portuguese|punjabi|russian|scotland|serbian|sinhala|somali|sport|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|ws|yoruba|zhongwen):variant(/simp|/trad|/cyr|/lat)?/:assetUri([a-z0-9-_+]{0,}[0-9]{8,}):amp(.amp)?:lite(.lite)?"`;

Expand All @@ -18,7 +18,7 @@ exports[`regex utils snapshots should create expected regex from getLegacyAssetR

exports[`regex utils snapshots should create expected regex from getLiveRadioRegex 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|archive|azeri|bengali|burmese|cymrufyw|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|naidheachdan|nepali|news|newsround|pashto|persian|pidgin|portuguese|punjabi|russian|scotland|serbian|sinhala|somali|sport|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|ws|yoruba|zhongwen)/:masterBrand(bbc_[a-z]+_radio)/:mediaId(liveRadio):lite(.lite)?"`;

exports[`regex utils snapshots should create expected regex from getManifestRegex 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|azeri|bengali|burmese|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|nepali|pashto|persian|pidgin|portuguese|punjabi|russian|scotland|serbian|sinhala|somali|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|ws|yoruba|zhongwen)/manifest.json"`;
exports[`regex utils snapshots should create expected regex from getManifestRegex 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|azeri|bengali|burmese|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|nepali|pashto|persian|pidgin|portuguese|punjabi|russian|serbian|sinhala|somali|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|ws|yoruba|zhongwen)/manifest.json"`;

exports[`regex utils snapshots should create expected regex from getMostReadDataRegex 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|archive|azeri|bengali|burmese|cymrufyw|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|naidheachdan|nepali|news|newsround|pashto|persian|pidgin|portuguese|punjabi|russian|scotland|serbian|sinhala|somali|sport|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|ws|yoruba|zhongwen)/mostread:variant(/simp|/trad|/cyr|/lat)?.json"`;

Expand All @@ -36,6 +36,6 @@ exports[`regex utils snapshots should create expected regex from getRecommendati

exports[`regex utils snapshots should create expected regex from getSecondaryColumnDataRegex 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|archive|azeri|bengali|burmese|cymrufyw|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|naidheachdan|nepali|news|newsround|pashto|persian|pidgin|portuguese|punjabi|russian|scotland|serbian|sinhala|somali|sport|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|ws|yoruba|zhongwen)/sty-secondary-column:variant(/simp|/trad|/cyr|/lat)?.json"`;

exports[`regex utils snapshots should create expected regex from getSwRegex 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|archive|azeri|bengali|burmese|cymrufyw|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|naidheachdan|nepali|news|newsround|pashto|persian|pidgin|portuguese|punjabi|russian|scotland|serbian|sinhala|somali|sport|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|ws|yoruba|zhongwen)/sw.js"`;
exports[`regex utils snapshots should create expected regex from getSwRegex 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|azeri|bengali|burmese|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|nepali|pashto|persian|pidgin|portuguese|punjabi|russian|serbian|sinhala|somali|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|ws|yoruba|zhongwen)/sw.js"`;

exports[`regex utils snapshots should create expected regex from getTopicPageRegex 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|archive|azeri|bengali|burmese|cymrufyw|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|naidheachdan|nepali|news|newsround|pashto|persian|pidgin|portuguese|punjabi|russian|scotland|serbian|sinhala|somali|sport|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|ws|yoruba|zhongwen)/topics/:id([a-z0-9]+)?:variant(/simp|/trad|/cyr|/lat)?:lite(.lite)?"`;
13 changes: 7 additions & 6 deletions src/app/routes/utils/regex/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ export const getArticleRegex = services => {
return `/:service(${serviceRegex})?:discipline(${sportDisciplineRegex})?/:local(${articleLocalRegex})/:id(${idRegex}):variant(${variantRegex})?:nonCanonicalArticleRenderPlatform(${nonCanonicalArticleRenderPlatform})?`;
};

export const getArticleSwRegex = services => {
const serviceRegex = getServiceRegex(services);
return `/:service(${serviceRegex})/:local(${articleLocalRegex})/sw.js`;
};

const getWorldServices = services => {
const publicServices = [
'news',
Expand All @@ -35,11 +30,17 @@ const getWorldServices = services => {
'cymrufyw',
'naidheachdan',
'archive',
'scotland',
];

return services.filter(service => !publicServices.includes(service));
};

export const getArticleSwRegex = services => {
const serviceRegex = getServiceRegex(getWorldServices(services));
return `/:service(${serviceRegex})/:local(${articleLocalRegex})/sw.js`;
Copy link
Contributor

Choose a reason for hiding this comment

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

Given that the articleLocalRegex was for the public services, does it now make sense to remove this, and hardcode articles instead...?

Suggested change
return `/:service(${serviceRegex})/:local(${articleLocalRegex})/sw.js`;
return `/:service(${serviceRegex})/articles/sw.js`;

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea. Updated

};

export const getArticleManifestRegex = services => {
const serviceRegex = getServiceRegex(getWorldServices(services));
return `/:service(${serviceRegex})/:local(${articleLocalRegex})/manifest.json`;
Copy link
Contributor

@karinathomasbbc karinathomasbbc Mar 26, 2025

Choose a reason for hiding this comment

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

This is potentially out of scope (or is it? - Let's get a second opinion!) Let's do this while we're here: per my comment above anything that uses getWorldServices no longer needs articleLocalRegex. If we did change it, we would also need to update some tests.

(Note that this we recently removed manifest paths from Public Services, and we just missed this.

Suggested change
export const getArticleManifestRegex = services => {
const serviceRegex = getServiceRegex(getWorldServices(services));
return `/:service(${serviceRegex})/:local(${articleLocalRegex})/manifest.json`;
export const getArticleManifestRegex = services => {
const serviceRegex = getServiceRegex(getWorldServices(services));
return `/:service(${serviceRegex})/articles/manifest.json`;

Copy link
Member Author

Choose a reason for hiding this comment

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

That makes sense. Updated

Expand All @@ -51,7 +52,7 @@ export const getHomePageRegex = services => {
};

export const getSwRegex = services => {
const serviceRegex = getServiceRegex(services);
const serviceRegex = getServiceRegex(getWorldServices(services));
return `/:service(${serviceRegex})/sw.js`;
};

Expand Down
2 changes: 1 addition & 1 deletion src/server/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,7 @@ describe('Server', () => {

describe('Service workers', () => {
it('should serve a file for existing service workers', async () => {
Copy link
Contributor

@karinathomasbbc karinathomasbbc Mar 31, 2025

Choose a reason for hiding this comment

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

Can we make sure there's still a test for existence of /world-service/sw.js? (choose one of the world services as an example)

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops, we should def keep it. Updated

await makeRequest('/news/articles/sw.js');
await makeRequest('/gahuza/articles/sw.js');
expect(sendFileSpy.mock.calls[0][0]).toEqual(
path.join(__dirname, '/public/sw.js'),
);
Expand Down
Loading