dino-express
Version:
DinO enabled REST framework based on express
58 lines • 2.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.LambdaResponseAdaptor = void 0;
// Copyright 2022 Quirino Brizi [quirino.brizi@gmail.com]
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
const dino_core_1 = require("dino-core");
const Helper_1 = require("../../Helper");
class LambdaResponseAdaptor {
responseAsBase64;
/**
* Valid values are proxy and method, need to create an enum
*/
integrationType;
constructor(environment) {
this.responseAsBase64 = environment.getOrDefault('dino:server:response:asBase64', false);
// if there is a typo default to method integration type...
this.integrationType = environment.getOrDefault('dino:cloud:integration', 'method');
}
adapt(response) {
const res = this.integrationType === 'proxy' ? this.buildAWSProxyResponse(response) : this.buildAWSResponse(response);
dino_core_1.Logger.debug(`sending response ${JSON.stringify(res)} built for ${this.integrationType} on AWS Lambda`);
return res;
}
buildAWSResponse(response) {
const headers = response.getHeaders() ?? {};
headers['X-Cloud-Provider'] = 'AWS';
return {
statusCode: response.statusCode ?? 200,
headers,
body: Helper_1.Helper.buildResponseBody(response, false, this.responseAsBase64),
isBase64Encoded: this.responseAsBase64
};
}
buildAWSProxyResponse(response) {
const headers = response.getHeaders() ?? {};
headers['X-Cloud-Provider'] = 'AWS';
return {
statusCode: response.statusCode ?? 200,
headers,
multiValueHeaders: {},
body: Helper_1.Helper.buildResponseBody(response, true, this.responseAsBase64),
isBase64Encoded: this.responseAsBase64
};
}
}
exports.LambdaResponseAdaptor = LambdaResponseAdaptor;
//# sourceMappingURL=LambdaResponseAdaptor.js.map