Skip to content

Commit 50779aa

Browse files
Revert "feat(common/core): Added useGlobalPrefix option for Controllers"
1 parent 110f27b commit 50779aa

3 files changed

Lines changed: 9 additions & 39 deletions

File tree

packages/common/constants.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ export const METADATA = {
88
export const SHARED_MODULE_METADATA = '__module:shared__';
99
export const GLOBAL_MODULE_METADATA = '__module:global__';
1010
export const PATH_METADATA = 'path';
11-
export const PATH_PREFIX_METADATA = 'path:globalPrefix';
1211
export const PARAMTYPES_METADATA = 'design:paramtypes';
1312
export const SELF_DECLARED_DEPS_METADATA = 'self:paramtypes';
1413
export const OPTIONAL_DEPS_METADATA = 'optional:paramtypes';

packages/common/decorators/core/controller.decorator.ts

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import {
2-
PATH_METADATA,
3-
PATH_PREFIX_METADATA,
4-
SCOPE_OPTIONS_METADATA,
5-
} from '../../constants';
1+
import { PATH_METADATA, SCOPE_OPTIONS_METADATA } from '../../constants';
62
import { isString, isUndefined } from '../../utils/shared.utils';
73
import { ScopeOptions } from '../../interfaces/scope-options.interface';
84

@@ -13,22 +9,12 @@ import { ScopeOptions } from '../../interfaces/scope-options.interface';
139
*/
1410
export interface ControllerOptions extends ScopeOptions {
1511
/**
16-
* Specifies an optional `route path prefix`. The prefix is pre-pended to the
12+
* Specifies an optional `route path prefix`. The prefix is pre-pended to the
1713
* path specified in any request decorator in the class.
1814
*
1915
* @see [Routing](https://docs.nestjs.com/controllers#routing)
2016
*/
2117
path?: string;
22-
23-
/**
24-
* Specifies an optional setting for enabling/disabling the use of app's
25-
* GlobalPrefix. In other words, a switch to remove the prefix set using
26-
* `setGlobalPrefix()` only for this controller.
27-
*
28-
* @see [Routing](https://docs.nestjs.com/controllers#routing)
29-
* @see [Global path prefix](https://docs.nestjs.com/faq/global-prefix)
30-
*/
31-
useGlobalPrefix?: boolean;
3218
}
3319

3420
/**
@@ -127,10 +113,8 @@ export function Controller(options: ControllerOptions): ClassDecorator;
127113
* - `scope` - symbol that determines the lifetime of a Controller instance.
128114
* [See Scope](https://docs.nestjs.com/fundamentals/injection-scopes#usage) for
129115
* more details.
130-
* - `path` - string that defines a `route path prefix`. The prefix
116+
* - `prefix` - string that defines a `route path prefix`. The prefix
131117
* is pre-pended to the path specified in any request decorator in the class.
132-
* - `useGlobalPrefix` - a boolean value that enables/disables the setting done
133-
* using `setGlobalPrefix()`.
134118
*
135119
* @see [Routing](https://docs.nestjs.com/controllers#routing)
136120
* @see [Controllers](https://docs.nestjs.com/controllers)
@@ -143,22 +127,14 @@ export function Controller(
143127
prefixOrOptions?: string | ControllerOptions,
144128
): ClassDecorator {
145129
const defaultPath = '/';
146-
const defaultUseGlobalPrefix = true;
147-
const [path, useGlobalPrefix, scopeOptions] = isUndefined(prefixOrOptions)
148-
? [defaultPath, defaultUseGlobalPrefix, undefined]
130+
const [path, scopeOptions] = isUndefined(prefixOrOptions)
131+
? [defaultPath, undefined]
149132
: isString(prefixOrOptions)
150-
? [prefixOrOptions, defaultUseGlobalPrefix, undefined]
151-
: [
152-
prefixOrOptions.path || defaultPath,
153-
!isUndefined(prefixOrOptions)
154-
? Boolean(prefixOrOptions.useGlobalPrefix)
155-
: defaultUseGlobalPrefix,
156-
{ scope: prefixOrOptions.scope },
157-
];
133+
? [prefixOrOptions, undefined]
134+
: [prefixOrOptions.path || defaultPath, { scope: prefixOrOptions.scope }];
158135

159136
return (target: object) => {
160137
Reflect.defineMetadata(PATH_METADATA, path, target);
161138
Reflect.defineMetadata(SCOPE_OPTIONS_METADATA, scopeOptions, target);
162-
Reflect.defineMetadata(PATH_PREFIX_METADATA, useGlobalPrefix, target);
163139
};
164140
}

packages/core/router/router-explorer.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import { HttpServer } from '@nestjs/common';
2-
import {
3-
PATH_METADATA,
4-
METHOD_METADATA,
5-
PATH_PREFIX_METADATA,
6-
} from '@nestjs/common/constants';
2+
import { METHOD_METADATA, PATH_METADATA } from '@nestjs/common/constants';
73
import { RequestMethod } from '@nestjs/common/enums/request-method.enum';
84
import { Controller } from '@nestjs/common/interfaces/controllers/controller.interface';
95
import { Type } from '@nestjs/common/interfaces/type.interface';
@@ -92,8 +88,7 @@ export class RouterExplorer {
9288
prefix?: string,
9389
): string {
9490
let path = Reflect.getMetadata(PATH_METADATA, metatype);
95-
const usePrefix = Reflect.getMetadata(PATH_PREFIX_METADATA, metatype);
96-
if (prefix && usePrefix) path = prefix + this.validateRoutePath(path);
91+
if (prefix) path = prefix + this.validateRoutePath(path);
9792
return this.validateRoutePath(path);
9893
}
9994

0 commit comments

Comments
 (0)