refactor: Simplify regex usage in sitemap tests and improve middleware formatting

This commit is contained in:
Nawaz Dhandala
2025-08-19 10:05:59 +01:00
parent 4988b9fc7a
commit 17bdfee012
2 changed files with 19 additions and 16 deletions

View File

@@ -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();

View File

@@ -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;