UNPKG

@tsed/platform-aws

Version:
55 lines 2 kB
import { PlatformBuilder } from "@tsed/common"; import { createServer, proxy } from "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`) export const 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" ]; export class PlatformAws { static bootstrap(module, settings = {}) { const platform = PlatformBuilder.create(module, { ...settings, adapter: settings.platform || settings.adapter || PlatformBuilder.adapter }); this.promise = platform.bootstrap().then(PlatformAws.onInit); return PlatformAws; } static callback() { return async (event, context) => { await PlatformAws.promise; return proxy(PlatformAws.awsServer, event, context, "PROMISE").promise; }; } static async onInit(platform) { PlatformAws.platform = platform; const binaryMimeTypes = platform.settings.get("aws.binaryMimeTypes", BYNARY_MIME_TYPES); await platform.callHook("$beforeListen"); // create Aws server PlatformAws.awsServer = createServer(platform.callback(), PlatformAws.onListen, binaryMimeTypes); } static async onListen() { const { platform } = PlatformAws; await platform.callHook("$afterListen"); await platform.injector.emit("$afterListen"); await platform.ready(); } } //# sourceMappingURL=PlatformAws.js.map