-
Notifications
You must be signed in to change notification settings - Fork 2
Application
The application is the entry point of the application. It is responsible for starting the application and configuring
the application. The Application
class abstracts the underlying framework and provides a common interface for
starting the application. Currently @smoke-trees/postgres-backend supports only express
framework.
Here is signature for the Application class:
export declare class Application extends RouteHandler {
private readonly app;
private readonly controllers;
protected readonly port: string;
protected mw: RequestHandler[];
settings: Settings;
database: Database | null;
/**
* Creates a Application which can run as a server
* @param settings Settings Object to be used by the application
*/
constructor(settings: Settings);
/**
* Creates a Application which can run as a server
* @param settings Settings Object to be used by the application
* @param database Database Object to be used by the application
*/
constructor(settings: Settings, database: Database);
/**
* Loads all the middlewares added to the application
* @returns Returns the HTTP Server running the application
*/
run(): Promise<Server>;
/**
* Loads all the middlewares added to the application
* @returns Returns the express application
*/
getApp(): ExpressApplication;
/**
* Loads all the controllers added to the application
*/
loadControllers(): void;
/**
* Adds a controller to the application
* @param controller Controller to be added to the application
*/
addController(controller: Controller): void;
/**
* Adds global middlewares to the application
* @param middleware Middlewares to be added to the application
*/
addMiddleWare(...middleware: RequestHandler[]): void;
}
The Application class extends the Router class that exposes addMiddleWare
to add middlewares to the application. The Application class also exposes
addController
to add controllers to the application. The run
method
starts the application and returns the HTTP server running the application.
getApp
method returns the express application object. The loadControllers
method loads all the controllers added to the application and is called inside run.
With ❤️ from Smoketrees Digital LLP