@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.
58 lines (55 loc) • 1.92 kB
TypeScript
import { IncomingMessage, ServerResponse } from 'http';
import { I as ILogger } from '../../logger-F8qccesk.js';
import { F as FrameworkContract } from '../../framework.contract-td-lRvq6.js';
/**
* The framework that asynchronously instantiates your application and forwards the request to the framework as quickly as possible.
*
* @example
* ```typescript
* import express from 'express';
* import { ServerlessAdapter } from '@h4ad/serverless-adapter';
* import { ExpressFramework } from '@h4ad/serverless-adapter/lib/frameworks/express';
* import { LazyFramework } from '@h4ad/serverless-adapter/lib/frameworks/lazy';
*
* const expressFramework = new ExpressFramework();
* const factory = async () => {
* const app = express();
*
* // do some asynchronous stuffs like create the database;
* await new Promise(resolve => setTimeout(resolve, 100);
*
* return app;
* };
* const framework = new LazyFramework(expressFramework, factory);
*
* export const handler = ServerlessAdapter.new(null)
* .setFramework(framework)
* // set other configurations and then build
* .build();
* ```
*
* @breadcrumb Frameworks / LazyFramework
* @public
*/
declare class LazyFramework<TApp> implements FrameworkContract<null> {
protected readonly framework: FrameworkContract<TApp>;
protected readonly factory: () => Promise<TApp>;
protected readonly logger: ILogger;
/**
* Default Constructor
*/
constructor(framework: FrameworkContract<TApp>, factory: () => Promise<TApp>, logger?: ILogger);
/**
* The cached version of the app
*/
protected cachedApp?: TApp;
/**
* The delayed factory to create an instance of the app
*/
protected readonly delayedFactory: Promise<void>;
/**
* {@inheritDoc}
*/
sendRequest(_app: null, request: IncomingMessage, response: ServerResponse): void;
}
export { LazyFramework };