1 | import { IOpenable } from 'pip-services3-commons-node';
|
2 | import { IConfigurable } from 'pip-services3-commons-node';
|
3 | import { IReferenceable } from 'pip-services3-commons-node';
|
4 | import { IReferences } from 'pip-services3-commons-node';
|
5 | import { ConfigParams } from 'pip-services3-commons-node';
|
6 | import { Schema } from 'pip-services3-commons-node';
|
7 | import { IRegisterable } from './IRegisterable';
|
8 | /**
|
9 | * Used for creating HTTP endpoints. An endpoint is a URL, at which a given service can be accessed by a client.
|
10 | *
|
11 | * ### Configuration parameters ###
|
12 | *
|
13 | * Parameters to pass to the [[configure]] method for component configuration:
|
14 | *
|
15 | * - cors_headers - a comma-separated list of allowed CORS headers
|
16 | * - cors_origins - a comma-separated list of allowed CORS origins
|
17 | * - connection(s) - the connection resolver's connections:
|
18 | * - "connection.discovery_key" - the key to use for connection resolving in a discovery service;
|
19 | * - "connection.protocol" - the connection's protocol;
|
20 | * - "connection.host" - the target host;
|
21 | * - "connection.port" - the target port;
|
22 | * - "connection.uri" - the target URI.
|
23 | * - credential - the HTTPS credentials:
|
24 | * - "credential.ssl_key_file" - the SSL private key in PEM
|
25 | * - "credential.ssl_crt_file" - the SSL certificate in PEM
|
26 | * - "credential.ssl_ca_file" - the certificate authorities (root cerfiticates) in PEM
|
27 | *
|
28 | * ### References ###
|
29 | *
|
30 | * A logger, counters, and a connection resolver can be referenced by passing the
|
31 | * following references to the object's [[setReferences]] method:
|
32 | *
|
33 | * - logger: <code>"\*:logger:\*:\*:1.0"</code>;
|
34 | * - counters: <code>"\*:counters:\*:\*:1.0"</code>;
|
35 | * - discovery: <code>"\*:discovery:\*:\*:1.0"</code> (for the connection resolver).
|
36 | *
|
37 | * ### Examples ###
|
38 | *
|
39 | * public MyMethod(_config: ConfigParams, _references: IReferences) {
|
40 | * let endpoint = new HttpEndpoint();
|
41 | * if (this._config)
|
42 | * endpoint.configure(this._config);
|
43 | * if (this._references)
|
44 | * endpoint.setReferences(this._references);
|
45 | * ...
|
46 | *
|
47 | * this._endpoint.open(correlationId, (err) => {
|
48 | * this._opened = err == null;
|
49 | * callback(err);
|
50 | * });
|
51 | * ...
|
52 | * }
|
53 | */
|
54 | export declare class HttpEndpoint implements IOpenable, IConfigurable, IReferenceable {
|
55 | private static readonly _defaultConfig;
|
56 | private _server;
|
57 | private _connectionResolver;
|
58 | private _logger;
|
59 | private _counters;
|
60 | private _maintenanceEnabled;
|
61 | private _fileMaxSize;
|
62 | private _protocolUpgradeEnabled;
|
63 | private _uri;
|
64 | private _registrations;
|
65 | private _allowedHeaders;
|
66 | private _allowedOrigins;
|
67 | /**
|
68 | * Configures this HttpEndpoint using the given configuration parameters.
|
69 | *
|
70 | * __Configuration parameters:__
|
71 | * - cors_headers - a comma-separated list of allowed CORS headers
|
72 | * - cors_origins - a comma-separated list of allowed CORS origins
|
73 | * - __connection(s)__ - the connection resolver's connections;
|
74 | * - "connection.discovery_key" - the key to use for connection resolving in a discovery service;
|
75 | * - "connection.protocol" - the connection's protocol;
|
76 | * - "connection.host" - the target host;
|
77 | * - "connection.port" - the target port;
|
78 | * - "connection.uri" - the target URI.
|
79 | * - "credential.ssl_key_file" - SSL private key in PEM
|
80 | * - "credential.ssl_crt_file" - SSL certificate in PEM
|
81 | * - "credential.ssl_ca_file" - Certificate authority (root certificate) in PEM
|
82 | *
|
83 | * @param config configuration parameters, containing a "connection(s)" section.
|
84 | *
|
85 | * @see [[https://pip-services3-node.github.io/pip-services3-commons-node/classes/config.configparams.html ConfigParams]] (in the PipServices "Commons" package)
|
86 | */
|
87 | configure(config: ConfigParams): void;
|
88 | /**
|
89 | * Sets references to this endpoint's logger, counters, and connection resolver.
|
90 | *
|
91 | * __References:__
|
92 | * - logger: <code>"\*:logger:\*:\*:1.0"</code>
|
93 | * - counters: <code>"\*:counters:\*:\*:1.0"</code>
|
94 | * - discovery: <code>"\*:discovery:\*:\*:1.0"</code> (for the connection resolver)
|
95 | *
|
96 | * @param references an IReferences object, containing references to a logger, counters,
|
97 | * and a connection resolver.
|
98 | *
|
99 | * @see [[https://pip-services3-node.github.io/pip-services3-commons-node/interfaces/refer.ireferences.html IReferences]] (in the PipServices "Commons" package)
|
100 | */
|
101 | setReferences(references: IReferences): void;
|
102 | /**
|
103 | * Gets an HTTP server instance.
|
104 | * @returns an HTTP server instance of <code>null</code> if endpoint is closed.
|
105 | */
|
106 | getServer(): any;
|
107 | /**
|
108 | * @returns whether or not this endpoint is open with an actively listening REST server.
|
109 | */
|
110 | isOpen(): boolean;
|
111 | /**
|
112 | * Opens a connection using the parameters resolved by the referenced connection
|
113 | * resolver and creates a REST server (service) using the set options and parameters.
|
114 | *
|
115 | * @param correlationId (optional) transaction id to trace execution through call chain.
|
116 | * @param callback (optional) the function to call once the opening process is complete.
|
117 | * Will be called with an error if one is raised.
|
118 | */
|
119 | open(correlationId: string, callback?: (err: any) => void): void;
|
120 | private addCompatibility;
|
121 | private noCache;
|
122 | private doMaintenance;
|
123 | /**
|
124 | * Closes this endpoint and the REST server (service) that was opened earlier.
|
125 | *
|
126 | * @param correlationId (optional) transaction id to trace execution through call chain.
|
127 | * @param callback (optional) the function to call once the closing process is complete.
|
128 | * Will be called with an error if one is raised.
|
129 | */
|
130 | close(correlationId: string, callback?: (err: any) => void): void;
|
131 | /**
|
132 | * Registers a registerable object for dynamic endpoint discovery.
|
133 | *
|
134 | * @param registration the registration to add.
|
135 | *
|
136 | * @see [[IRegisterable]]
|
137 | */
|
138 | register(registration: IRegisterable): void;
|
139 | /**
|
140 | * Unregisters a registerable object, so that it is no longer used in dynamic
|
141 | * endpoint discovery.
|
142 | *
|
143 | * @param registration the registration to remove.
|
144 | *
|
145 | * @see [[IRegisterable]]
|
146 | */
|
147 | unregister(registration: IRegisterable): void;
|
148 | private performRegistrations;
|
149 | private fixRoute;
|
150 | /**
|
151 | * Returns correlationId from request
|
152 | * @param req - http request
|
153 | * @return Returns correlationId from request
|
154 | */
|
155 | getCorrelationId(req: any): string;
|
156 | /**
|
157 | * Registers an action in this objects REST server (service) by the given method and route.
|
158 | *
|
159 | * @param method the HTTP method of the route.
|
160 | * @param route the route to register in this object's REST server (service).
|
161 | * @param schema the schema to use for parameter validation.
|
162 | * @param action the action to perform at the given route.
|
163 | */
|
164 | registerRoute(method: string, route: string, schema: Schema, action: (req: any, res: any) => void): void;
|
165 | /**
|
166 | * Registers an action with authorization in this objects REST server (service)
|
167 | * by the given method and route.
|
168 | *
|
169 | * @param method the HTTP method of the route.
|
170 | * @param route the route to register in this object's REST server (service).
|
171 | * @param schema the schema to use for parameter validation.
|
172 | * @param authorize the authorization interceptor
|
173 | * @param action the action to perform at the given route.
|
174 | */
|
175 | registerRouteWithAuth(method: string, route: string, schema: Schema, authorize: (req: any, res: any, next: () => void) => void, action: (req: any, res: any) => void): void;
|
176 | /**
|
177 | * Registers a middleware action for the given route.
|
178 | *
|
179 | * @param route the route to register in this object's REST server (service).
|
180 | * @param action the middleware action to perform at the given route.
|
181 | */
|
182 | registerInterceptor(route: string, action: (req: any, res: any, next: () => void) => void): void;
|
183 | }
|