Skip to content
This repository was archived by the owner on Feb 1, 2026. It is now read-only.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

136 Commits

Repository files navigation

A generic application which uses internally a service container and a middleware dispatcher to handle any context object.

import{createApplication}from'@aldojs/application'letapp=createApplication()// add a sum handlerapp.use(({ a, b })=>a+b)// handle the contextletresult=app.handle({a: 1,b: -1})

Middlewares

Middlewares could be a common or an async function. please refer to @aldojs/middleware for more information on how middlewares are dispatched.

// Handler function signaturedeclaretypeMiddleware=(ctx: Context,next: ()=>any)=>any;

You can register as many middlewares as needed with the application's method .use(fn).

// to add a handler directly in the stackapp.use(middleware)

Context

The context is a plain object, containing all data needed by the middlewares to do their job. A proxied version is passed to the middleware chain, instead of the original context object, to provide the same fields, in addition to the properties defined with .set(key, value) or .bind(key, factory) methods. In other, you can access the services registered within the application, directly in the middlewares

declareinterfaceContext{[key: string]: any;}

You may use Application::set(key, instance) to share instances between contexts, like a DB connection or a global logger.

importMongoosefrom'mongoose'// set up the mongon db connection// let connection = ...// register it within the contextapp.set('db',connection)

You may also use .bind(key, fn) to bind per-context instances. This method takes the field name, and the factory function to create the service object on demand.

letoptions={/* some session options */}// a new instance of Session is `lazily` created for each contextapp.bind('session',()=>newSession(options))

.has(key) and .get(key) are aldo available to check the existence of a certain service or to get a previously defined one.

About

Generic application for Node.js projects

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages