mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
refactor: Simplify regex usage in sitemap tests and improve middleware formatting
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user