@@ -18,17 +18,6 @@ export class Http {
1818 * Only initialize the server without booting it.
1919 */
2020 public static async init ( options ?: HttpOptions ) : Promise < ServerImpl > {
21- options = Options . create ( options , {
22- initOnly : false ,
23- host : Config . get ( 'http.host' , '127.0.0.1' ) ,
24- port : Config . get ( 'http.port' , 3000 ) ,
25- routePath : Config . get ( 'rc.http.route' , Path . routes ( `http.${ Path . ext ( ) } ` ) ) ,
26- kernelPath : Config . get (
27- 'rc.http.kernel' ,
28- '@athenna/http/kernels/HttpKernel'
29- )
30- } )
31-
3221 const server = ioc . safeUse ( 'Athenna/Core/HttpServer' )
3322
3423 debug ( 'booting http application with options %o' , options )
@@ -46,12 +35,28 @@ export class Http {
4635 * Boot the Http application.
4736 */
4837 public static async boot ( options ?: HttpOptions ) : Promise < ServerImpl > {
38+ options = Options . create ( options , {
39+ initOnly : false ,
40+ isAWSLambda : false ,
41+ host : Config . get ( 'http.host' , '127.0.0.1' ) ,
42+ port : Config . get ( 'http.port' , 3000 ) ,
43+ routePath : Config . get ( 'rc.http.route' , Path . routes ( `http.${ Path . ext ( ) } ` ) ) ,
44+ kernelPath : Config . get (
45+ 'rc.http.kernel' ,
46+ '@athenna/http/kernels/HttpKernel'
47+ )
48+ } )
49+
4950 const server = await this . init ( options )
5051
5152 if ( options . initOnly ) {
5253 return server
5354 }
5455
56+ if ( options . isAWSLambda ) {
57+ return this . resolveAWSLambdaProxy ( server )
58+ }
59+
5560 await server . listen ( { host : options . host , port : options . port } )
5661
5762 if ( Config . notExists ( 'rc.bootLogs' ) || Config . is ( 'rc.bootLogs' , false ) ) {
@@ -110,4 +115,21 @@ export class Http {
110115 )
111116 }
112117 }
118+
119+ /**
120+ * Resolve the AWS Lambda proxy.
121+ */
122+ private static async resolveAWSLambdaProxy ( server : ServerImpl ) {
123+ const awsLambda = await Module . safeImport ( '@athenna/http/awslambda' )
124+
125+ if ( awsLambda ?. default ) {
126+ return awsLambda . default ( server . fastify )
127+ }
128+
129+ if ( ! awsLambda ) {
130+ throw new Error ( 'The library @fastify/aws-lambda is not installed' )
131+ }
132+
133+ return awsLambda ( server . fastify )
134+ }
113135}
0 commit comments