WebSocket Middleware Decorator
This file defines the Middleware
class decorator for the @sodacore/core
WebSocket (WS) module. It marks a class as WebSocket middleware, attaches the necessary metadata for discovery, and ensures the class is registered as providing WebSocket services. Middleware classes should implement the IMiddleware
interface.
Features
- Middleware Registration: Adds metadata to register the class as middleware within the Sodacore WebSocket framework.
- Service Tagging: Tags the middleware as providing WebSocket 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 './decorators/middleware';
@Middleware()
export class MyWsMiddleware {
async use(context, next) {
// Middleware logic here
await next();
}
}
API
Middleware(): ClassDecorator
- Returns: A class decorator function that registers the class as WebSocket middleware.
How It Works
- Sets the
type
metadata to'middleware'
for autowiring. - Adds
'ws'
to the class'sservices
metadata array for service discovery. - The metadata set by this decorator is used by the framework to discover and execute middleware in the WebSocket request pipeline.
Notes
- Middleware classes should implement the
IMiddleware
interface to ensure compatibility. - This decorator is intended for use with WebSocket middleware classes in the Sodacore framework.