Files
hope-food-pantry-app/src/url.ts
T
blake f1a46e2ba7 feat: add volunteer shift signup app
Initial source, tests, migrations, and local Docker setup for the Hope Food Pantry volunteer scheduler.
2026-10-16 09:33:39 -05:00

21 lines
901 B
TypeScript

import type { AppConfig } from './config.js';
/** Prefix an app path with BASE_PATH. The path must start with /. */
export function appPath(config: Pick<AppConfig, 'basePath'>, pathname: string): string {
if (!pathname.startsWith('/')) {
throw new Error(`App paths must start with /. Received ${pathname}.`);
}
if (pathname === '/') return config.basePath === '' ? '/' : config.basePath;
return `${config.basePath}${pathname}`;
}
/** Absolute public URL for redirects, assets, cookies' companion links, and mail. */
export function absoluteUrl(config: Pick<AppConfig, 'baseUrl' | 'basePath'>, pathname: string): string {
return `${config.baseUrl}${appPath(config, pathname)}`;
}
/** Cookie Path attribute. An empty mount prefix uses the site root. */
export function cookiePath(config: Pick<AppConfig, 'basePath'>): string {
return config.basePath === '' ? '/' : config.basePath;
}