1 | ;
|
2 | /**
|
3 | * Copyright 2018 Google Inc. All Rights Reserved.
|
4 | *
|
5 | * Licensed under the Apache License, Version 2.0 (the "License");
|
6 | * you may not use this file except in compliance with the License.
|
7 | * You may obtain a copy of the License at
|
8 | *
|
9 | * http://www.apache.org/licenses/LICENSE-2.0
|
10 | *
|
11 | * Unless required by applicable law or agreed to in writing, software
|
12 | * distributed under the License is distributed on an "AS IS" BASIS,
|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14 | * See the License for the specific language governing permissions and
|
15 | * limitations under the License.
|
16 | */
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.express = exports.Express = void 0;
|
19 | const common = require("../common");
|
20 | /** @hidden */
|
21 | class Express {
|
22 | handle(standard) {
|
23 | return (request, response) => {
|
24 | const metadata = {
|
25 | request,
|
26 | response,
|
27 | };
|
28 | standard(request.body, request.headers, { express: metadata })
|
29 | .then(({ status, body, headers }) => {
|
30 | if (headers) {
|
31 | for (const key in headers) {
|
32 | response.setHeader(key, headers[key]);
|
33 | }
|
34 | }
|
35 | response.status(status).send(body);
|
36 | })
|
37 | .catch((e) => {
|
38 | common.error(e.stack || e);
|
39 | response.status(500).send({ error: e.message || e });
|
40 | });
|
41 | };
|
42 | }
|
43 | isResponse(second) {
|
44 | return typeof second.send === 'function';
|
45 | }
|
46 | isRequest(first) {
|
47 | return typeof first.get === 'function';
|
48 | }
|
49 | check(first, second) {
|
50 | return this.isRequest(first) && this.isResponse(second);
|
51 | }
|
52 | }
|
53 | exports.Express = Express;
|
54 | /** @hidden */
|
55 | exports.express = new Express();
|
56 | //# sourceMappingURL=express.js.map |
\ | No newline at end of file |