website refactor
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { routes, routeMatchers } from '../../../apps/website/lib/routing/RouteConfig';
|
||||
import { stableUuidFromSeedKey } from '../../../adapters/bootstrap/racing/SeedIdHelper';
|
||||
import { seedId } from '../../../adapters/bootstrap/racing/SeedIdHelper';
|
||||
|
||||
export type RouteAccess = 'public' | 'auth' | 'admin' | 'sponsor';
|
||||
export type RouteParams = Record<string, string>;
|
||||
@@ -13,14 +13,20 @@ export interface WebsiteRouteDefinition {
|
||||
}
|
||||
|
||||
export class WebsiteRouteManager {
|
||||
// Generate IDs the same way the seed does for postgres compatibility
|
||||
// Generate IDs the same way the seed does
|
||||
private static getPersistenceMode(): 'postgres' | 'inmemory' {
|
||||
const mode = (process.env.GRIDPILOT_API_PERSISTENCE as 'postgres' | 'inmemory') || 'postgres';
|
||||
console.log(`[WebsiteRouteManager] Persistence mode: ${mode}`);
|
||||
return mode;
|
||||
}
|
||||
|
||||
private static readonly IDs = {
|
||||
LEAGUE: stableUuidFromSeedKey('league-1'),
|
||||
DRIVER: stableUuidFromSeedKey('driver-1'),
|
||||
TEAM: stableUuidFromSeedKey('team-1'),
|
||||
RACE: stableUuidFromSeedKey('race-1'),
|
||||
PROTEST: stableUuidFromSeedKey('protest-1'),
|
||||
} as const;
|
||||
get LEAGUE() { return seedId('league-1', WebsiteRouteManager.getPersistenceMode()); },
|
||||
get DRIVER() { return seedId('driver-1', WebsiteRouteManager.getPersistenceMode()); },
|
||||
get TEAM() { return seedId('team-1', WebsiteRouteManager.getPersistenceMode()); },
|
||||
get RACE() { return seedId('race-1', WebsiteRouteManager.getPersistenceMode()); },
|
||||
get PROTEST() { return seedId('protest-1', WebsiteRouteManager.getPersistenceMode()); },
|
||||
};
|
||||
|
||||
public resolvePathTemplate(pathTemplate: string, params: RouteParams = {}): string {
|
||||
return pathTemplate.replace(/\[([^\]]+)\]/g, (_match, key) => {
|
||||
@@ -43,11 +49,16 @@ export class WebsiteRouteManager {
|
||||
});
|
||||
};
|
||||
|
||||
const processGroup = (groupRoutes: Record<string, string | ((id: string) => string)>) => {
|
||||
const processGroup = (group: keyof typeof routes, groupRoutes: Record<string, string | ((id: string) => string)>) => {
|
||||
Object.values(groupRoutes).forEach((value) => {
|
||||
if (typeof value === 'function') {
|
||||
const template = value(WebsiteRouteManager.IDs.LEAGUE);
|
||||
pushRoute(template, { id: WebsiteRouteManager.IDs.LEAGUE });
|
||||
let id = WebsiteRouteManager.IDs.LEAGUE;
|
||||
if (group === 'driver') id = WebsiteRouteManager.IDs.DRIVER;
|
||||
if (group === 'team') id = WebsiteRouteManager.IDs.TEAM;
|
||||
if (group === 'race') id = WebsiteRouteManager.IDs.RACE;
|
||||
|
||||
const template = value(id);
|
||||
pushRoute(template, { id });
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -55,16 +66,16 @@ export class WebsiteRouteManager {
|
||||
});
|
||||
};
|
||||
|
||||
processGroup(routes.auth);
|
||||
processGroup(routes.public);
|
||||
processGroup(routes.protected);
|
||||
processGroup(routes.sponsor);
|
||||
processGroup(routes.admin);
|
||||
processGroup(routes.league);
|
||||
processGroup(routes.race);
|
||||
processGroup(routes.team);
|
||||
processGroup(routes.driver);
|
||||
processGroup(routes.error);
|
||||
processGroup('auth', routes.auth);
|
||||
processGroup('public', routes.public);
|
||||
processGroup('protected', routes.protected);
|
||||
processGroup('sponsor', routes.sponsor);
|
||||
processGroup('admin', routes.admin);
|
||||
processGroup('league', routes.league);
|
||||
processGroup('race', routes.race);
|
||||
processGroup('team', routes.team);
|
||||
processGroup('driver', routes.driver);
|
||||
processGroup('error', routes.error);
|
||||
|
||||
return result.sort((a, b) => a.pathTemplate.localeCompare(b.pathTemplate));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user