Skip to content

Commit 9724f4e

Browse files
fix: Address code review feedback
- Improve route conflict detection example (use semantically identical patterns) - Extract isProductionEnvironment() helper to avoid duplication - Enhance documentation clarity All tests still passing (244/244) Co-authored-by: xuyushun441-sys <255036401+xuyushun441-sys@users.noreply.github.com>
1 parent 16cc350 commit 9724f4e

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

packages/core/src/api-registry.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,9 @@ export class ApiRegistry {
307307
*
308308
* NOTE: This implementation uses exact string matching for route conflict detection.
309309
* It works well for static paths but has limitations with parameterized routes.
310-
* For example, `/api/users/:id` and `/api/users/detail` will NOT be detected as conflicts
311-
* even though they may overlap at runtime depending on the routing library.
310+
* For example, `/api/users/:id` and `/api/users/:userId` will NOT be detected as conflicts
311+
* even though they are semantically identical parameterized patterns. Similarly,
312+
* `/api/:resource/list` and `/api/:entity/list` would also not be detected as conflicting.
312313
*
313314
* For more advanced conflict detection (e.g., path-to-regexp pattern matching),
314315
* consider integrating with your routing library's conflict detection mechanism.
@@ -580,7 +581,7 @@ export class ApiRegistry {
580581
* ```
581582
*/
582583
clear(options: { force?: boolean } = {}): void {
583-
const isProduction = process.env.NODE_ENV === 'production';
584+
const isProduction = this.isProductionEnvironment();
584585

585586
if (isProduction && !options.force) {
586587
throw new Error(
@@ -719,4 +720,15 @@ export class ApiRegistry {
719720
}
720721
}
721722
}
723+
724+
/**
725+
* Check if running in production environment
726+
*
727+
* @returns true if NODE_ENV is 'production'
728+
* @private
729+
* @internal
730+
*/
731+
private isProductionEnvironment(): boolean {
732+
return process.env.NODE_ENV === 'production';
733+
}
722734
}

0 commit comments

Comments
 (0)