Files

115 lines
6.4 KiB
TypeScript

import { index, route, type RouteConfig } from "@react-router/dev/routes";
import { remixConfigRoutes } from "@react-router/remix-config-routes-adapter";
import { dirname } from "node:path";
import { fileURLToPath } from "node:url";
import { createRoutesFromFolders } from "./utils/compat/v1-route-convention";
const appDirectory = dirname(fileURLToPath(import.meta.url));
export const defaultIgnoredRouteFilePatterns = [
"**/.*",
"**/*.css",
"**/*.test.ts",
"**/*.test.tsx",
"**/*.spec.ts",
"**/*.spec.tsx",
"**/*.server.ts",
"**/*.server.tsx",
"customer-portal/**",
] as const;
export const defaultDisabledPluginRouteFilePatterns = [
"admin/email-marketing.tsx",
"admin/email-marketing/**",
"admin/knowledge-base.tsx",
"admin/knowledge-base/**",
"help/**",
"internal/api/__workflows/**",
"mcp/**",
] as const;
export const localPreviewRouteFilePatterns = ["**/*[_]dev.customer-portal-preview.settings.tsx"] as const;
export const createCoreRouteConfig = (environment = process.env.NODE_ENV) =>
remixConfigRoutes(async (defineRoutes) => {
return createRoutesFromFolders(defineRoutes, {
appDirectory,
ignoredFilePatterns: [
...defaultIgnoredRouteFilePatterns,
...defaultDisabledPluginRouteFilePatterns,
...(environment === "production" ? localPreviewRouteFilePatterns : []),
],
});
});
export const createPortalRouteConfig = () =>
[
// Operational routes stay available on the isolated portal runtime without
// importing the Core file-route manifest.
route("healthz", "routes/healthz.tsx"),
route("readyz", "routes/readyz.tsx"),
route("healthcheck", "routes/healthcheck.tsx"),
route("api/metrics", "routes/api.metrics.ts", { id: "routes/api.metrics.portal" }),
route(":tenant", "routes/customer-portal/layout.tsx", { id: "routes/customer-portal/layout" }, [
index("routes/customer-portal/dashboard.tsx", { id: "routes/customer-portal/dashboard" }),
route("projects", "routes/customer-portal/projects.tsx", { id: "routes/customer-portal/projects" }),
route("upload", "routes/customer-portal/upload.tsx", { id: "routes/customer-portal/upload" }),
route("settings", "routes/customer-portal/settings.tsx", { id: "routes/customer-portal/settings" }),
route("branding/logo", "routes/customer-portal/branding-logo.ts", { id: "routes/customer-portal/branding-logo" }),
route("exports/:exportId", "routes/customer-portal/export-download.ts", { id: "routes/customer-portal/export-download" }),
route("projects/:projectId/upload", "routes/customer-portal/project-upload.ts", { id: "routes/customer-portal/project-upload" }),
route("projects/:projectId/complaints/:formId", "routes/customer-portal/project-complaint.ts", {
id: "routes/customer-portal/project-complaint",
}),
route("projects/:projectId", "routes/customer-portal/project-detail.tsx", { id: "routes/customer-portal/project-detail" }),
route("documents/:releaseId", "routes/customer-portal/document-download.ts", { id: "routes/customer-portal/document-download" }),
route("logout", "routes/customer-portal/logout.ts", { id: "routes/customer-portal/logout" }),
route("*", "routes/customer-portal/auth.tsx", { id: "routes/customer-portal/auth" }),
]),
// A verified custom host exposes the same portal surface without a tenant
// slug. The outer host router injects the trusted tenant context before
// this pathless alias tree is reached. Explicit auth prefixes outrank the
// standard `:tenant` index route, so `/login` can never hydrate as a
// dashboard for a tenant literally named `login`.
route(null, "routes/customer-portal/layout.tsx", { id: "routes/customer-portal/layout.__custom-host" }, [
index("routes/customer-portal/custom-host-dispatch.tsx", { id: "routes/customer-portal/dashboard.__custom-host" }),
route("projects", "routes/customer-portal/custom-host-dispatch.tsx", { id: "routes/customer-portal/projects.__custom-host" }),
route("upload", "routes/customer-portal/custom-host-dispatch.tsx", { id: "routes/customer-portal/upload.__custom-host" }),
route("settings", "routes/customer-portal/custom-host-dispatch.tsx", { id: "routes/customer-portal/settings.__custom-host" }),
route("branding/logo", "routes/customer-portal/branding-logo.ts", { id: "routes/customer-portal/branding-logo.__custom-host" }),
route("exports/:exportId", "routes/customer-portal/custom-host-dispatch.tsx", {
id: "routes/customer-portal/export-download.__custom-host",
}),
route("projects/:projectId/upload", "routes/customer-portal/custom-host-dispatch.tsx", {
id: "routes/customer-portal/project-upload.__custom-host",
}),
route("projects/:projectId/complaints/:formId", "routes/customer-portal/custom-host-dispatch.tsx", {
id: "routes/customer-portal/project-complaint.__custom-host",
}),
route("projects/:projectId", "routes/customer-portal/custom-host-dispatch.tsx", {
id: "routes/customer-portal/project-detail.__custom-host",
}),
route("documents/:releaseId", "routes/customer-portal/custom-host-dispatch.tsx", {
id: "routes/customer-portal/document-download.__custom-host",
}),
route("logout", "routes/customer-portal/custom-host-dispatch.tsx", { id: "routes/customer-portal/logout.__custom-host" }),
route("login/*", "routes/customer-portal/custom-host-dispatch.tsx", { id: "routes/customer-portal/auth.login.__custom-host" }),
route("forgot-password", "routes/customer-portal/custom-host-dispatch.tsx", {
id: "routes/customer-portal/auth.forgot-password.__custom-host",
}),
route("setup/*", "routes/customer-portal/custom-host-dispatch.tsx", { id: "routes/customer-portal/auth.setup.__custom-host" }),
route("verify-email/*", "routes/customer-portal/custom-host-dispatch.tsx", {
id: "routes/customer-portal/auth.verify-email.__custom-host",
}),
route("reset-password/*", "routes/customer-portal/custom-host-dispatch.tsx", {
id: "routes/customer-portal/auth.reset-password.__custom-host",
}),
]),
] satisfies RouteConfig;
// react-router.config.ts validates this build-only environment contract before
// invoking route discovery. The fallback keeps direct unit imports deterministic.
const buildSurface = process.env.HIVEGRID_RUNTIME_SURFACE === "portal" ? "portal" : "core";
export default (buildSurface === "portal" ? createPortalRouteConfig() : createCoreRouteConfig()) satisfies RouteConfig;