ba-web-framework/src/controllers/BaseController.ts
Alan Bridgeman 621222d69d
All checks were successful
Publish to Private NPM Registry / publish (push) Successful in 33s
Moved joinPaths to BaseController as a protected static function + refactored large chunks of Router to work with the new stuff
2026-01-12 16:54:56 -06:00

26 lines
No EOL
899 B
TypeScript

import type { Application } from 'express';
export abstract class BaseController {
/** Helper function to join paths cleanly */
protected static joinPaths(base: string, path: string): string {
// Combine the base path and the specific route path
let fullPath = base + path;
// Remove double slashes (e.g., //user -> /user)
fullPath = fullPath.replace(/\/\//g, '/');
// Ensure it starts with / (in case base was empty and path was empty)
if (!fullPath.startsWith('/')) {
fullPath = '/' + fullPath;
}
// Remove trailing slash (optional, unless it's just root '/')
if (fullPath.length > 1 && fullPath.endsWith('/')) {
fullPath = fullPath.slice(0, -1);
}
return fullPath;
}
static setup(app: Application) {}
}