From 17bdfee012e20fad2e4ebc89cd78b567ad29d47c Mon Sep 17 00:00:00 2001 From: Nawaz Dhandala Date: Tue, 19 Aug 2025 10:05:59 +0100 Subject: [PATCH] refactor: Simplify regex usage in sitemap tests and improve middleware formatting --- E2E/Tests/Home/Sitemap.spec.ts | 10 +++++----- Home/Routes.ts | 25 ++++++++++++++----------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/E2E/Tests/Home/Sitemap.spec.ts b/E2E/Tests/Home/Sitemap.spec.ts index 703868f869..ca81b4bb8b 100644 --- a/E2E/Tests/Home/Sitemap.spec.ts +++ b/E2E/Tests/Home/Sitemap.spec.ts @@ -49,19 +49,19 @@ test.describe("Home: Sitemap", () => { // Ensure at least one dynamic section appears const hasBlog: boolean = locs.some((l: string) => { - return /\/blog\b/.test(l); + return (/\/blog\b/).test(l); }); const hasCompare: boolean = locs.some((l: string) => { - return /\/compare\//.test(l); + return (/\/compare\//).test(l); }); const hasProductPages: boolean = locs.some((l: string) => { - return /\/product\//.test(l); + return (/\/product\//).test(l); }); const hasDocs: boolean = locs.some((l: string) => { - return /\/docs\//.test(l); + return (/\/docs\//).test(l); }); const hasLegal: boolean = locs.some((l: string) => { - return /\/legal\//.test(l); + return (/\/legal\//).test(l); }); expect(hasBlog).toBeTruthy(); expect(hasCompare).toBeTruthy(); diff --git a/Home/Routes.ts b/Home/Routes.ts index 06f6333f21..4e2ef869f8 100755 --- a/Home/Routes.ts +++ b/Home/Routes.ts @@ -33,18 +33,21 @@ const HomeFeatureSet: FeatureSet = { //Routes // Middleware to inject baseUrl for templates (used for canonical links) - app.use(async (_req: ExpressRequest, res: ExpressResponse, next: () => void) => { - if (!res.locals['homeUrl']) { - try { - res.locals['homeUrl'] = (await DatabaseConfig.getHomeUrl()).toString().replace(/\/$/, ""); - } catch (err) { - // Fallback hard-coded production domain if env misconfigured - res.locals['homeUrl'] = "https://oneuptime.com"; + app.use( + async (_req: ExpressRequest, res: ExpressResponse, next: () => void) => { + if (!res.locals["homeUrl"]) { + try { + res.locals["homeUrl"] = (await DatabaseConfig.getHomeUrl()) + .toString() + .replace(/\/$/, ""); + } catch (_err) { + // Fallback hard-coded production domain if env misconfigured + res.locals["homeUrl"] = "https://oneuptime.com"; + } } - } - next(); - }); - + next(); + }, + ); app.get("/", (_req: ExpressRequest, res: ExpressResponse) => { const { reviewsList1, reviewsList2, reviewsList3 } = Reviews;