Skip to content

Middleware Decorator

This file defines the Middleware class decorator for the @sodacore/core HTTP module. It marks a class as HTTP middleware, attaches the necessary metadata for discovery, and ensures the class is registered as providing HTTP services. Middleware classes should implement the IMiddleware interface.


Features

  • Middleware Registration: Adds metadata to register the class as middleware within the Sodacore framework.
  • Service Tagging: Tags the middleware as providing HTTP services for internal discovery and execution.
  • Autowiring Support: Sets the type metadata to enable automatic dependency injection and lifecycle management.

Usage

typescript
import Middleware from './decorator/middleware';

@Middleware()
export class MyMiddleware {
	async use(context, next) {
		// Middleware logic here
		await next();
	}
}

API

Middleware(): ClassDecorator

  • Returns: A class decorator function that registers the class as HTTP middleware.

How It Works

  • Sets the type metadata to 'middleware' for autowiring.
  • Adds 'http' to the class's services metadata array for service discovery.
  • The metadata set by this decorator is used by the framework to discover and execute middleware in the HTTP request pipeline.

Notes

  • Middleware classes should implement the IMiddleware interface to ensure compatibility.
  • This decorator is intended for use with HTTP middleware classes in the Sodacore framework.

Released under the Apache-2.0 License.