1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | import {BindingKey, Context, CoreBindings} from '@loopback/core';
|
7 | import {DEFAULT_MIDDLEWARE_CHAIN, InvokeMiddleware} from '@loopback/express';
|
8 | import {HttpProtocol} from '@loopback/http-server';
|
9 | import {OpenApiSpec, OperationObject} from '@loopback/openapi-v3';
|
10 | import https from 'https';
|
11 | import {ErrorWriterOptions} from 'strong-error-handler';
|
12 | import {BodyParser, RequestBodyParser} from './body-parsers';
|
13 | import {HttpHandler} from './http-handler';
|
14 | import {RestServer, RestServerConfig} from './rest.server';
|
15 | import {ResolvedRoute, RestRouter, RestRouterOptions} from './router';
|
16 | import {SequenceHandler} from './sequence';
|
17 | import {
|
18 | AjvFactory,
|
19 | FindRoute,
|
20 | InvokeMethod,
|
21 | LogError,
|
22 | OperationArgs,
|
23 | OperationRetval,
|
24 | ParseParams,
|
25 | Reject,
|
26 | Request,
|
27 | RequestBodyParserOptions,
|
28 | Response,
|
29 | Send,
|
30 | } from './types';
|
31 |
|
32 |
|
33 |
|
34 |
|
35 | export namespace RestBindings {
|
36 | |
37 |
|
38 |
|
39 | export const CONFIG: BindingKey<RestServerConfig> =
|
40 | CoreBindings.APPLICATION_CONFIG.deepProperty('rest');
|
41 | |
42 |
|
43 |
|
44 | export const HOST = BindingKey.create<string | undefined>('rest.host');
|
45 | |
46 |
|
47 |
|
48 | export const PORT = BindingKey.create<number>('rest.port');
|
49 | |
50 |
|
51 |
|
52 | export const PATH = BindingKey.create<string | undefined>('rest.path');
|
53 | |
54 |
|
55 |
|
56 | export const URL = BindingKey.create<string>('rest.url');
|
57 | |
58 |
|
59 |
|
60 | export const PROTOCOL = BindingKey.create<HttpProtocol>('rest.protocol');
|
61 | |
62 |
|
63 |
|
64 | export const HTTPS_OPTIONS =
|
65 | BindingKey.create<https.ServerOptions>('rest.httpsOptions');
|
66 |
|
67 | |
68 |
|
69 |
|
70 | export const SERVER = BindingKey.create<RestServer>('servers.RestServer');
|
71 |
|
72 | |
73 |
|
74 |
|
75 | export const BASE_PATH = BindingKey.create<string>('rest.basePath');
|
76 |
|
77 | |
78 |
|
79 |
|
80 | export const HANDLER = BindingKey.create<HttpHandler>('rest.handler');
|
81 |
|
82 | |
83 |
|
84 |
|
85 | export const ROUTER = BindingKey.create<RestRouter>('rest.router');
|
86 |
|
87 | export const ROUTER_OPTIONS = BindingKey.create<RestRouterOptions>(
|
88 | 'rest.router.options',
|
89 | );
|
90 |
|
91 | |
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 | export const ERROR_WRITER_OPTIONS = BindingKey.create<ErrorWriterOptions>(
|
100 | 'rest.errorWriterOptions',
|
101 | );
|
102 |
|
103 | |
104 |
|
105 |
|
106 | export const REQUEST_BODY_PARSER_OPTIONS =
|
107 | BindingKey.create<RequestBodyParserOptions>(
|
108 | 'rest.requestBodyParserOptions',
|
109 | );
|
110 |
|
111 | |
112 |
|
113 |
|
114 | export const REQUEST_BODY_PARSER = BindingKey.create<RequestBodyParser>(
|
115 | 'rest.requestBodyParser',
|
116 | );
|
117 |
|
118 | function bodyParserBindingKey(parser: string) {
|
119 | return `${REQUEST_BODY_PARSER}.${parser}`;
|
120 | }
|
121 |
|
122 | |
123 |
|
124 |
|
125 | export const REQUEST_BODY_PARSER_JSON = BindingKey.create<BodyParser>(
|
126 | bodyParserBindingKey('JsonBodyParser'),
|
127 | );
|
128 |
|
129 | |
130 |
|
131 |
|
132 | export const REQUEST_BODY_PARSER_URLENCODED = BindingKey.create<BodyParser>(
|
133 | bodyParserBindingKey('UrlEncodedBodyParser'),
|
134 | );
|
135 |
|
136 | |
137 |
|
138 |
|
139 | export const REQUEST_BODY_PARSER_TEXT = BindingKey.create<BodyParser>(
|
140 | bodyParserBindingKey('TextBodyParser'),
|
141 | );
|
142 |
|
143 | |
144 |
|
145 |
|
146 | export const REQUEST_BODY_PARSER_RAW = BindingKey.create<BodyParser>(
|
147 | bodyParserBindingKey('RawBodyParser'),
|
148 | );
|
149 |
|
150 | |
151 |
|
152 |
|
153 | export const REQUEST_BODY_PARSER_STREAM = BindingKey.create<BodyParser>(
|
154 | bodyParserBindingKey('StreamBodyParser'),
|
155 | );
|
156 |
|
157 | |
158 |
|
159 |
|
160 | export const AJV_FACTORY = BindingKey.create<AjvFactory>(
|
161 | bodyParserBindingKey('rest.ajvFactory'),
|
162 | );
|
163 |
|
164 | |
165 |
|
166 |
|
167 | export const API_SPEC: BindingKey<OpenApiSpec> =
|
168 | BindingKey.create<OpenApiSpec>('rest.apiSpec');
|
169 |
|
170 | |
171 |
|
172 |
|
173 | export const OPERATION_SPEC_CURRENT = BindingKey.create<OperationObject>(
|
174 | 'rest.operationSpec.current',
|
175 | );
|
176 |
|
177 | |
178 |
|
179 |
|
180 | export const SEQUENCE = BindingKey.create<SequenceHandler>('rest.sequence');
|
181 |
|
182 | |
183 |
|
184 |
|
185 |
|
186 | export const INVOKE_MIDDLEWARE_SERVICE = BindingKey.create<InvokeMiddleware>(
|
187 | 'rest.invokeMiddleware',
|
188 | );
|
189 |
|
190 | |
191 |
|
192 |
|
193 | export namespace SequenceActions {
|
194 | |
195 |
|
196 |
|
197 | export const INVOKE_MIDDLEWARE = BindingKey.create<InvokeMiddleware>(
|
198 | 'rest.sequence.actions.invokeMiddleware',
|
199 | );
|
200 | |
201 |
|
202 |
|
203 | export const FIND_ROUTE = BindingKey.create<FindRoute>(
|
204 | 'rest.sequence.actions.findRoute',
|
205 | );
|
206 | |
207 |
|
208 |
|
209 | export const PARSE_PARAMS = BindingKey.create<ParseParams>(
|
210 | 'rest.sequence.actions.parseParams',
|
211 | );
|
212 | |
213 |
|
214 |
|
215 | export const INVOKE_METHOD = BindingKey.create<InvokeMethod>(
|
216 | 'rest.sequence.actions.invokeMethod',
|
217 | );
|
218 | |
219 |
|
220 |
|
221 | export const LOG_ERROR = BindingKey.create<LogError>(
|
222 | 'rest.sequence.actions.logError',
|
223 | );
|
224 | |
225 |
|
226 |
|
227 | export const SEND = BindingKey.create<Send>('rest.sequence.actions.send');
|
228 | |
229 |
|
230 |
|
231 | export const REJECT = BindingKey.create<Reject>(
|
232 | 'rest.sequence.actions.reject',
|
233 | );
|
234 | }
|
235 |
|
236 | export namespace Operation {
|
237 | export const ROUTE = BindingKey.create<ResolvedRoute>(
|
238 | 'rest.operation.route',
|
239 | );
|
240 |
|
241 | export const PARAMS = BindingKey.create<OperationArgs>(
|
242 | 'rest.operation.params',
|
243 | );
|
244 |
|
245 | export const RETURN_VALUE = BindingKey.create<OperationRetval>(
|
246 | 'rest.operation.returnValue',
|
247 | );
|
248 | }
|
249 |
|
250 | |
251 |
|
252 |
|
253 | export namespace Http {
|
254 | |
255 |
|
256 |
|
257 | export const REQUEST: BindingKey<Request> =
|
258 | BindingKey.create<Request>('rest.http.request');
|
259 | |
260 |
|
261 |
|
262 | export const RESPONSE = BindingKey.create<Response>('rest.http.response');
|
263 | |
264 |
|
265 |
|
266 | export const CONTEXT = BindingKey.create<Context>(
|
267 | 'rest.http.request.context',
|
268 | );
|
269 | }
|
270 |
|
271 | |
272 |
|
273 |
|
274 | export const ROUTES = 'routes';
|
275 | }
|
276 |
|
277 |
|
278 |
|
279 |
|
280 | export namespace RestTags {
|
281 | |
282 |
|
283 |
|
284 | export const REST_ROUTE = 'restRoute';
|
285 |
|
286 | |
287 |
|
288 |
|
289 | export const ROUTE_VERB = 'restRouteVerb';
|
290 |
|
291 | |
292 |
|
293 |
|
294 | export const ROUTE_PATH = 'restRoutePath';
|
295 |
|
296 | |
297 |
|
298 |
|
299 | export const CONTROLLER_ROUTE = 'controllerRoute';
|
300 |
|
301 | |
302 |
|
303 |
|
304 |
|
305 | export const CONTROLLER_BINDING = 'controllerBinding';
|
306 |
|
307 | export const AJV_KEYWORD = 'ajvKeyword';
|
308 | export const AJV_FORMAT = 'ajvFormat';
|
309 |
|
310 | export const REST_MIDDLEWARE_CHAIN = DEFAULT_MIDDLEWARE_CHAIN;
|
311 |
|
312 | |
313 |
|
314 |
|
315 | export const ACTION_MIDDLEWARE_CHAIN = 'middlewareChain.rest.actions';
|
316 | }
|