@h4ad/serverless-adapter
Version:
Run REST APIs and other web applications using your existing Node.js application framework (NestJS, Express, Koa, Hapi, Fastify and many others), on top of AWS, Azure, Digital Ocean and many other clouds.
2 lines • 2.04 kB
JavaScript
import{C as W,a as l,f as u,h as w,y as P,z as v}from"../../chunk-6BLWJRLG.mjs";import{a as m}from"../../chunk-QWPVIX2T.mjs";import"node:stream";import{inspect as C}from"node:util";var x=class extends l{constructor(e){super();this.options=e}static{m(this,"AwsStreamHandler")}getHandler(e,t,d,a,s,E,r){return awslambda.streamifyResponse(async(o,A,n)=>{this.options?.callbackWaitsForEmptyEventLoop!==void 0&&(n.callbackWaitsForEmptyEventLoop=this.options.callbackWaitsForEmptyEventLoop);let R={response:A,context:n};this.onReceiveRequest(r,o,R,s,E);let p=this.getAdapterByEventAndContext(o,R,d,r);this.onResolveAdapter(r,p),u({event:o,context:n}),await this.forwardRequestToFramework(e,t,o,R,p,s,r)})}onReceiveRequest(e,t,d,a,s){e.debug("SERVERLESS_ADAPTER:PROXY",()=>({event:t,context:C(d,{depth:null}),binarySettings:a,respondWithErrors:s}))}onResolveAdapter(e,t){e.debug("SERVERLESS_ADAPTER:RESOLVED_ADAPTER_NAME: ",t.getAdapterName())}onResolveRequestValues(e,t){e.debug("SERVERLESS_ADAPTER:FORWARD_REQUEST_TO_FRAMEWORK:REQUEST_VALUES",()=>({requestValues:{...t,body:t.body?.toString()}}))}onForwardResponseAdapterResponse(e,t){e.debug("SERVERLESS_ADAPTER:FORWARD_RESPONSE:EVENT_SOURCE_RESPONSE",{successResponse:t})}async forwardRequestToFramework(e,t,d,a,s,E,r){let o=s.getRequest(d,a,r);this.onResolveRequestValues(r,o);let A=new v({method:o.method,headers:o.headers,body:o.body,remoteAddress:o.remoteAddress,url:o.path}),n=new W({method:o.method,onReceiveHeaders:m((R,p)=>{let c=w(p),i={statusCode:R,headers:c},S=p["set-cookie"];S&&(i.cookies=Array.isArray(S)?S:[S],delete p["set-cookie"],delete c["set-cookie"]),this.onForwardResponseAdapterResponse(r,i);let y=awslambda.HttpResponseStream.from(a.response,i);return y.write(""),y},"onReceiveHeaders"),log:r});t.sendRequest(e,A,n),r.debug("SERVERLESS_ADAPTER:FORWARD_REQUEST_TO_FRAMEWORK:WAITING_STREAM_COMPLETE"),await P(n),r.debug("SERVERLESS_ADAPTER:FORWARD_REQUEST_TO_FRAMEWORK:STREAM_COMPLETE"),a.response.end()}};export{x as AwsStreamHandler};
//# sourceMappingURL=index.mjs.map