1/** 2 * Unified view registry with lazy loading 3 * 4 * Single source of truth for all routes, used by both server (SSR) and client (SPA). 5 * Uses dynamic imports for code splitting without build step. 6 * 7 * Server: Load view, render with uhtml-ssr 8 * Client: Lazy load view, hydrate with uhtml 9 */ 10 11// View registry with lazy imports 12// Each entry maps a path to a function that returns a promise for the view module 13export const views = { 14 '/': () => import('./landing.js'), 15 '/login': () => import('./login.js'), 16 '/register': () => import('./register.js'), 17 '/dashboard': () => import('./dashboard.js'), 18 '/subscription': () => import('./subscription.js'), 19 '/settings': () => import('./settings.js'), 20 '/privacy': () => import('./privacy.js'), 21 '/terms': () => import('./terms.js'), 22 '/support': () => import('./support.js'), 23 '/authorize-device': () => import('./authorize-device.js'), 24 '/auth/reset-password': () => import('./reset-password.js'), 25 '/auth/forgot-password': () => import('./forgot-password.js'), 26 '/auth/verify': () => import('./verify-email.js'), // client-only (polling) 27 '/404': () => import('./404.js'), 28}; 29 30/** 31 * Match a pathname to a view loader 32 * Returns the view loader function for the path, or the 404 view if not found 33 * 34 * @param {string} pathname - The pathname to match 35 * @returns {Function} View loader function that returns a promise for the view module 36 */ 37export const matchView = (pathname) => { 38 // Exact match 39 if (views[pathname]) { 40 return views[pathname]; 41 } 42 43 // No dynamic routes in this app - return 404 for non-matches 44 return views['/404']; 45}; 46 47/** 48 * Check if a route requires authentication 49 * Used by server to redirect unauthenticated users 50 * 51 * @param {string} pathname - The pathname to check 52 * @returns {boolean} True if the route requires authentication 53 */ 54export const requiresAuth = (pathname) => { 55 // Protected routes 56 const protectedRoutes = ['/dashboard', '/subscription', '/settings']; 57 return protectedRoutes.includes(pathname); 58}; 59 60/** 61 * Get all routes for reference (not used in runtime, but useful for debugging) 62 * @returns {string[]} Array of all registered paths 63 */ 64export const getAllPaths = () => Object.keys(views);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.