@@ -2,26 +2,139 @@ import { PATH_METADATA, SCOPE_OPTIONS_METADATA } from '../../constants';
22import { isString , isUndefined } from '../../utils/shared.utils' ;
33import { ScopeOptions } from './../../interfaces/scope-options.interface' ;
44
5+ /**
6+ * Interface defining options that can be passed to `@Controller()` decorator
7+ *
8+ * @publicApi
9+ */
510export interface ControllerOptions extends ScopeOptions {
11+ /**
12+ * Specifies an optional `route path prefix`. The prefix is pre-pended to the
13+ * path specified in any request decorator in the class.
14+ *
15+ * @see [Routing](https://docs.nestjs.com/controllers#routing)
16+ */
617 path ?: string ;
718}
819
20+ export function Controller ( ) ;
21+ export function Controller ( prefix : string ) ;
22+ export function Controller ( options : ControllerOptions ) ;
23+ /**
24+ * Decorator that marks a class as a Nest controller that can receive inbound
25+ * requests and produce responses.
26+ *
27+ * An HTTP Controller responds to inbound HTTP Requests and produces HTTP Responses.
28+ * It defines a class that provides the context for one or more related route
29+ * handlers that correspond to HTTP request methods and associated routes
30+ * for example `GET /api/profile`, `POST /user/resume`.
31+ *
32+ * A Microservice Controller responds to requests as well as events, running over
33+ * a variety of transports [(read more here)](https://docs.nestjs.com/microservices/basics).
34+ * It defines a class that provides a context for one or more message or event
35+ * handlers.
36+ *
37+ * @see [Controllers](https://docs.nestjs.com/controllers)
38+ * @see [Microservices](https://docs.nestjs.com/microservices/basics#request-response)
39+ *
40+ * @publicApi
41+ */
42+ export function Controller ( ) ;
43+
44+ /**
45+ * Decorator that marks a class as a Nest controller that can receive inbound
46+ * requests and produce responses.
47+ *
48+ * An HTTP Controller responds to inbound HTTP Requests and produces HTTP Responses.
49+ * It defines a class that provides the context for one or more related route
50+ * handlers that correspond to HTTP request methods and associated routes
51+ * for example `GET /api/profile`, `POST /user/resume`.
52+ *
53+ * A Microservice Controller responds to requests as well as events, running over
54+ * a variety of transports [(read more here)](https://docs.nestjs.com/microservices/basics).
55+ * It defines a class that provides a context for one or more message or event
56+ * handlers.
57+ *
58+ * @param {string } prefix string that defines a `route path prefix`. The prefix
59+ * is pre-pended to the path specified in any request decorator in the class.
60+ *
61+ * @see [Routing](https://docs.nestjs.com/controllers#routing)
62+ * @see [Controllers](https://docs.nestjs.com/controllers)
63+ * @see [Microservices](https://docs.nestjs.com/microservices/basics#request-response)
64+ *
65+ * @publicApi
66+ */
67+ export function Controller ( prefix : string ) ;
68+
69+ /**
70+ * Decorator that marks a class as a Nest controller that can receive inbound
71+ * requests and produce responses.
72+ *
73+ * An HTTP Controller responds to inbound HTTP Requests and produces HTTP Responses.
74+ * It defines a class that provides the context for one or more related route
75+ * handlers that correspond to HTTP request methods and associated routes
76+ * for example `GET /api/profile`, `POST /user/resume`.
77+ *
78+ * A Microservice Controller responds to requests as well as events, running over
79+ * a variety of transports [(read more here)](https://docs.nestjs.com/microservices/basics).
80+ * It defines a class that provides a context for one or more message or event
81+ * handlers.
82+ *
83+ * @param {object } options configuration object specifying:
84+ *
85+ * - `scope` - symbol that determines the lifetime of a Controller instance.
86+ * [See Scope](https://docs.nestjs.com/fundamentals/injection-scopes#usage) for
87+ * more details.
88+ * - `prefix` - string that defines a `route path prefix`. The prefix
89+ * is pre-pended to the path specified in any request decorator in the class.
90+ *
91+ * @see [Routing](https://docs.nestjs.com/controllers#routing)
92+ * @see [Controllers](https://docs.nestjs.com/controllers)
93+ * @see [Microservices](https://docs.nestjs.com/microservices/basics#request-response)
94+ *
95+ * @publicApi
96+ */
97+ export function Controller ( options : ControllerOptions ) ;
98+
999/**
10- * Defines the controller. Controller can inject dependencies through constructor.
11- * Those dependencies have to belong to the same module.
100+ * Decorator that marks a class as a Nest controller that can receive inbound
101+ * requests and produce responses.
102+ *
103+ * An HTTP Controller responds to inbound HTTP Requests and produces HTTP Responses.
104+ * It defines a class that provides the context for one or more related route
105+ * handlers that correspond to HTTP request methods and associated routes
106+ * for example `GET /api/profile`, `POST /user/resume`
107+ *
108+ * A Microservice Controller responds to requests as well as events, running over
109+ * a variety of transports [(read more here)](https://docs.nestjs.com/microservices/basics).
110+ * It defines a class that provides a context for one or more message or event
111+ * handlers.
112+ *
113+ * @param prefixOrOptions a `route path prefix` or a `ControllerOptions` object.
114+ * A `route path prefix` is pre-pended to the path specified in any request decorator
115+ * in the class. `ControllerOptions` is an options configuration object specifying:
116+ * - `scope` - symbol that determines the lifetime of a Controller instance.
117+ * [See Scope](https://docs.nestjs.com/fundamentals/injection-scopes#usage) for
118+ * more details.
119+ * - `prefix` - string that defines a `route path prefix`. The prefix
120+ * is pre-pended to the path specified in any request decorator in the class.
121+ *
122+ * @see [Routing](https://docs.nestjs.com/controllers#routing)
123+ * @see [Controllers](https://docs.nestjs.com/controllers)
124+ * @see [Microservices](https://docs.nestjs.com/microservices/basics#request-response)
125+ * @see [Scope](https://docs.nestjs.com/fundamentals/injection-scopes#usage)
126+ *
127+ * @publicApi
12128 */
13- export function Controller ( ) : ClassDecorator ;
14- export function Controller ( prefix : string ) : ClassDecorator ;
15- export function Controller ( options : ControllerOptions ) : ClassDecorator ;
16129export function Controller (
17130 prefixOrOptions ?: string | ControllerOptions ,
18131) : ClassDecorator {
19132 const defaultPath = '/' ;
20133 const [ path , scopeOptions ] = isUndefined ( prefixOrOptions )
21134 ? [ defaultPath , undefined ]
22135 : isString ( prefixOrOptions )
23- ? [ prefixOrOptions , undefined ]
24- : [ prefixOrOptions . path || defaultPath , { scope : prefixOrOptions . scope } ] ;
136+ ? [ prefixOrOptions , undefined ]
137+ : [ prefixOrOptions . path || defaultPath , { scope : prefixOrOptions . scope } ] ;
25138
26139 return ( target : object ) => {
27140 Reflect . defineMetadata ( PATH_METADATA , path , target ) ;
0 commit comments