Skip to main content

LazyFramework

@h4ad/serverless-adapter > LazyFramework

(class) LazyFramework

The framework that asynchronously instantiates your application and forwards the request to the framework as quickly as possible.

Signature:

export declare class LazyFramework<TApp> implements FrameworkContract<null> 

Implements: FrameworkContract <null>

Example

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();

(constructor)

Default Constructor

Signature:

constructor(framework: FrameworkContract<TApp>, factory: () => Promise<TApp>, logger?: ILogger);

Parameters

ParameterTypeDescription
frameworkFrameworkContract <TApp>
factory() => Promise<TApp>
loggerILogger(Optional)

(property) cachedApp

The cached version of the app

Signature:

protected cachedApp?: TApp;

(property) delayedFactory

The delayed factory to create an instance of the app

Signature:

protected readonly delayedFactory: Promise<void>;

(property) factory

Signature:

protected readonly factory: () => Promise<TApp>;

(property) framework

Signature:

protected readonly framework: FrameworkContract<TApp>;

(property) logger

Signature:

protected readonly logger: ILogger;

(method) sendRequest

Signature:

sendRequest(_app: null, request: IncomingMessage, response: ServerResponse): void;

Parameters

ParameterTypeDescription
_appnull
requestIncomingMessage
responseServerResponse

Returns:

void