1 | ;
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.Controller = void 0;
|
4 | const constants_1 = require("../../constants");
|
5 | const shared_utils_1 = require("../../utils/shared.utils");
|
6 | /**
|
7 | * Decorator that marks a class as a Nest controller that can receive inbound
|
8 | * requests and produce responses.
|
9 | *
|
10 | * An HTTP Controller responds to inbound HTTP Requests and produces HTTP Responses.
|
11 | * It defines a class that provides the context for one or more related route
|
12 | * handlers that correspond to HTTP request methods and associated routes
|
13 | * for example `GET /api/profile`, `POST /users/resume`
|
14 | *
|
15 | * A Microservice Controller responds to requests as well as events, running over
|
16 | * a variety of transports [(read more here)](https://docs.nestjs.com/microservices/basics).
|
17 | * It defines a class that provides a context for one or more message or event
|
18 | * handlers.
|
19 | *
|
20 | * @param prefixOrOptions a `route path prefix` or a `ControllerOptions` object.
|
21 | * A `route path prefix` is pre-pended to the path specified in any request decorator
|
22 | * in the class. `ControllerOptions` is an options configuration object specifying:
|
23 | * - `scope` - symbol that determines the lifetime of a Controller instance.
|
24 | * [See Scope](https://docs.nestjs.com/fundamentals/injection-scopes#usage) for
|
25 | * more details.
|
26 | * - `prefix` - string that defines a `route path prefix`. The prefix
|
27 | * is pre-pended to the path specified in any request decorator in the class.
|
28 | * - `version` - string, array of strings, or Symbol that defines the version
|
29 | * of all routes in the class. [See Versioning](https://docs.nestjs.com/techniques/versioning)
|
30 | * for more details.
|
31 | *
|
32 | * @see [Routing](https://docs.nestjs.com/controllers#routing)
|
33 | * @see [Controllers](https://docs.nestjs.com/controllers)
|
34 | * @see [Microservices](https://docs.nestjs.com/microservices/basics#request-response)
|
35 | * @see [Scope](https://docs.nestjs.com/fundamentals/injection-scopes#usage)
|
36 | * @see [Versioning](https://docs.nestjs.com/techniques/versioning)
|
37 | *
|
38 | * @publicApi
|
39 | */
|
40 | function Controller(prefixOrOptions) {
|
41 | const defaultPath = '/';
|
42 | const [path, host, scopeOptions, versionOptions] = shared_utils_1.isUndefined(prefixOrOptions)
|
43 | ? [defaultPath, undefined, undefined, undefined]
|
44 | : shared_utils_1.isString(prefixOrOptions) || Array.isArray(prefixOrOptions)
|
45 | ? [prefixOrOptions, undefined, undefined, undefined]
|
46 | : [
|
47 | prefixOrOptions.path || defaultPath,
|
48 | prefixOrOptions.host,
|
49 | { scope: prefixOrOptions.scope },
|
50 | prefixOrOptions.version,
|
51 | ];
|
52 | return (target) => {
|
53 | Reflect.defineMetadata(constants_1.PATH_METADATA, path, target);
|
54 | Reflect.defineMetadata(constants_1.HOST_METADATA, host, target);
|
55 | Reflect.defineMetadata(constants_1.SCOPE_OPTIONS_METADATA, scopeOptions, target);
|
56 | Reflect.defineMetadata(constants_1.VERSION_METADATA, versionOptions, target);
|
57 | };
|
58 | }
|
59 | exports.Controller = Controller;
|