Moved joinPaths to BaseController as a protected static function + refactored large chunks of Router to work with the new stuff
All checks were successful
Publish to Private NPM Registry / publish (push) Successful in 33s
All checks were successful
Publish to Private NPM Registry / publish (push) Successful in 33s
This commit is contained in:
parent
21b5e7e873
commit
621222d69d
3 changed files with 139 additions and 58 deletions
|
|
@ -1,5 +1,26 @@
|
|||
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) {}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue