feat: Add PublicDashboard frontend configuration and custom domain handling

This commit is contained in:
Nawaz Dhandala
2026-03-26 16:27:04 +00:00
parent c0fe56f54d
commit 5601cc5591

View File

@@ -24,6 +24,8 @@ import {
StatusPageData,
getStatusPageData,
} from "./Utils/StatusPage";
import DashboardDomainService from "Common/Server/Services/DashboardDomainService";
import DashboardDomain from "Common/Models/DatabaseModels/DashboardDomain";
const app: ExpressApplication = Express.getExpressApp();
@@ -148,6 +150,12 @@ const DashboardFrontendConfig: FrontendConfig = {
primaryHostOnly: true,
};
const PublicDashboardFrontendConfig: FrontendConfig = {
routePrefix: "/public-dashboard",
publicPath: PublicDashboardPublicPath,
indexViewPath: PublicDashboardViewPath,
};
const DashboardRootPwaFileMap: Array<{ route: string; file: string }> = [
{ route: "/manifest.json", file: "manifest.json" },
{ route: "/sw.js", file: "sw.js" },
@@ -405,7 +413,32 @@ const registerFrontendApp: (frontendConfig: FrontendConfig) => void = (
);
};
const registerStatusPageCustomDomainFallback: () => void = (): void => {
const isDashboardDomain: (hostname: string) => Promise<boolean> = async (
hostname: string,
): Promise<boolean> => {
try {
const dashboardDomain: DashboardDomain | null =
await DashboardDomainService.findOneBy({
query: {
fullDomain: hostname,
},
select: {
_id: true,
},
props: {
isRoot: true,
},
});
return dashboardDomain !== null;
} catch (err) {
logger.error("Error checking if domain is a dashboard domain:");
logger.error(err);
return false;
}
};
const registerCustomDomainFallback: () => void = (): void => {
app.get(
"*",
async (req: ExpressRequest, res: ExpressResponse, next: NextFunction) => {
@@ -417,6 +450,20 @@ const registerStatusPageCustomDomainFallback: () => void = (): void => {
return next();
}
// Check if this custom domain belongs to a PublicDashboard.
// If so, serve the PublicDashboard SPA instead of StatusPage.
const requestHostname: string = getRequestHostname(req);
if (requestHostname && (await isDashboardDomain(requestHostname))) {
return renderFrontendIndexPage({
req,
res,
next,
frontendConfig: PublicDashboardFrontendConfig,
});
}
// Default: serve StatusPage for custom domains
return renderFrontendIndexPage({
req,
res,
@@ -491,14 +538,10 @@ const init: PromiseVoidFunction = async (): Promise<void> => {
registerFrontendApp(StatusPageFrontendConfig);
registerFrontendApp({
routePrefix: "/public-dashboard",
publicPath: PublicDashboardPublicPath,
indexViewPath: PublicDashboardViewPath,
});
registerFrontendApp(PublicDashboardFrontendConfig);
registerDashboardRootPwaFiles();
registerStatusPageCustomDomainFallback();
registerCustomDomainFallback();
registerDashboardFallbackForPrimaryHost();
};