@tsed/platform-aws
Version:
Module to support AWS function with Ts.ED
59 lines • 2.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PlatformAws = exports.BYNARY_MIME_TYPES = void 0;
const common_1 = require("@tsed/common");
const aws_serverless_express_1 = require("aws-serverless-express");
// NOTE: If you get ERR_CONTENT_DECODING_FAILED in your browser, this is likely
// due to a compressed response (e.g. gzip) which has not been handled correctly
// by aws-serverless-express and/or API Gateway. Add the necessary MIME types to
// binaryMimeTypes below, then redeploy (`npm run package-deploy`)
exports.BYNARY_MIME_TYPES = [
"application/javascript",
"application/json",
"application/octet-stream",
"application/xml",
"font/eot",
"font/opentype",
"font/otf",
"image/jpeg",
"image/png",
"image/svg+xml",
"text/comma-separated-values",
"text/css",
"text/html",
"text/javascript",
"text/plain",
"text/text",
"text/xml"
];
class PlatformAws {
static bootstrap(module, settings = {}) {
const platform = common_1.PlatformBuilder.create(module, {
...settings,
adapter: settings.platform || settings.adapter || common_1.PlatformBuilder.adapter
});
this.promise = platform.bootstrap().then(PlatformAws.onInit);
return PlatformAws;
}
static callback() {
return async (event, context) => {
await PlatformAws.promise;
return (0, aws_serverless_express_1.proxy)(PlatformAws.awsServer, event, context, "PROMISE").promise;
};
}
static async onInit(platform) {
PlatformAws.platform = platform;
const binaryMimeTypes = platform.settings.get("aws.binaryMimeTypes", exports.BYNARY_MIME_TYPES);
await platform.callHook("$beforeListen");
// create Aws server
PlatformAws.awsServer = (0, aws_serverless_express_1.createServer)(platform.callback(), PlatformAws.onListen, binaryMimeTypes);
}
static async onListen() {
const { platform } = PlatformAws;
await platform.callHook("$afterListen");
await platform.injector.emit("$afterListen");
await platform.ready();
}
}
exports.PlatformAws = PlatformAws;
//# sourceMappingURL=PlatformAws.js.map