# PlatformContext Class
Module | import { PlatformContext } from "@tsed/common" |
---|---|
Source | /packages/common/src/platform/domain/PlatformContext.ts |
# Overview
class PlatformContext extends Map<any, any> {
/**
* Request id generated by @@contextMiddleware@@.
*
* ::: tip
* By default Ts.ED generate uuid like that `uuidv4().replace(/-/gi, ""))`.
* Dash are removed to simplify tracking logs in Kibana
* :::
*
* ::: tip
* Request id can by customized by changing the server configuration.
*
* ```typescript
* @Configuration({
* logger: {
* reqIdBuilder: createUniqId // give your own id generator function
* }
* })
* class Server {
*
* }
* ```
* :::
*
*/
readonly id: string;
/**
* Date when request have been handled by the server. @@RequestLogger@@ use this date to log request duration.
*/
readonly dateStart: Date;
/**
* The request container used by the Ts.ED DI. It contain all services annotated with `@Scope(ProviderScope.REQUEST)`
*/
container: LocalsContainer<any>;
/**
* The current @@EndpointMetadata@@ resolved by Ts.ED during the request.
*/
endpoint: EndpointMetadata;
/**
* The data return by the previous endpoint if you use multiple handler on the same route. By default data is empty.
*/
data: any;
/**
* Logger attached to the context request.
*/
logger: RequestLogger;
/**
* The current @@PlatformResponse@@.
*/
response: PlatformResponse;
/**
* The current @@PlatformRequest@@.
*/
request: PlatformRequest;
/**
*
*/
injector: InjectorService;
constructor({ id, injector, logger, response, request, endpoint, ...options }: RequestContextOptions);
get env(): import("@tsed/core").Env;
destroy(): Promise<void>;
emit(eventName: string, ...args: any[]): Promise<void>;
/**
* Return the original request instance.
*/
getRequest<T = any>(): T;
/**
* Return the original response instance.
*/
getResponse<T = any>(): T;
}
# Members
readonly id: string;
Request id generated by
TIP
By default Ts.ED generate uuid like that uuidv4().replace(/-/gi, ""))
.
Dash are removed to simplify tracking logs in Kibana
TIP
Request id can by customized by changing the server configuration.
@Configuration({
logger: {
reqIdBuilder: createUniqId // give your own id generator function
}
})
class Server {
}
2
3
4
5
6
7
8
:::
readonly dateStart: Date;
Date when request have been handled by the server.
container: LocalsContainer<any>;
The request container used by the Ts.ED DI. It contain all services annotated with @Scope(ProviderScope.REQUEST)
endpoint: EndpointMetadata;
The current
data: any;
The data return by the previous endpoint if you use multiple handler on the same route. By default data is empty.
logger: RequestLogger;
Logger attached to the context request.
response: PlatformResponse;
The current
request: PlatformRequest;
The current
injector: InjectorService;
get env(): import("@tsed/core").Env;
destroy(): Promise<void>;
emit(eventName: string, ...args: any[]): Promise<void>;
getRequest<T = any>(): T;
Return the original request instance.
getResponse<T = any>(): T;
Return the original response instance.
- Session & cookies
- Passport.js
- TypeORM
- Mongoose
- GraphQL
- Socket.io
- Swagger
- AJV
- Multer
- Serve static files
- Templating
- Throw HTTP Exceptions
- Customize 404
- AWS
- Jest
- Seq
- Controllers
- Providers
- Model
- Converters
- Middlewares
- Pipes
- Interceptors
- Authentication
- Hooks
- Injection scopes
- Custom providers
- Custom endpoint decorator
- Testing