# Class PlatformContext

Class
Module
import { PlatformContext } from "@tsed/common"
Source/packages/common/src/platform/domain/PlatformContext.ts

# Overview

class PlatformContext extends Map<any, any> {
<span class="token keyword">readonly</span> id<span class="token punctuation">:</span> <span class="token keyword">string</span><span class="token punctuation">;</span>

<span class="token keyword">readonly</span> dateStart<span class="token punctuation">:</span> <span class="token keyword">Date</span><span class="token punctuation">;</span>

container<span class="token punctuation">:</span> <a href="/api/di/domain/LocalsContainer.html"><span class="token">LocalsContainer</span></a>&lt;<span class="token keyword">any</span>&gt;<span class="token punctuation">;</span>

endpoint<span class="token punctuation">:</span> <a href="/api/common/mvc/models/EndpointMetadata.html"><span class="token">EndpointMetadata</span></a><span class="token punctuation">;</span>

data<span class="token punctuation">:</span> <span class="token keyword">any</span><span class="token punctuation">;</span>

logger<span class="token punctuation">:</span> <a href="/api/common/platform/domain/RequestLogger.html"><span class="token">RequestLogger</span></a><span class="token punctuation">;</span>

response<span class="token punctuation">:</span> <a href="/api/common/platform/services/PlatformResponse.html"><span class="token">PlatformResponse</span></a><span class="token punctuation">;</span>

request<span class="token punctuation">:</span> <a href="/api/common/platform/services/PlatformRequest.html"><span class="token">PlatformRequest</span></a><span class="token punctuation">;</span>

injector<span class="token punctuation">:</span> <a href="/api/di/services/InjectorService.html"><span class="token">InjectorService</span></a><span class="token punctuation">;</span>
<span class="token keyword">constructor</span><span class="token punctuation">(</span><span class="token punctuation">{</span> id<span class="token punctuation">,</span> injector<span class="token punctuation">,</span> logger<span class="token punctuation">,</span> response<span class="token punctuation">,</span> request<span class="token punctuation">,</span> endpoint<span class="token punctuation">,</span> ...options <span class="token punctuation">}</span><span class="token punctuation">:</span> <a href="/api/common/platform/domain/RequestContextOptions.html"><span class="token">RequestContextOptions</span></a><span class="token punctuation">)</span><span class="token punctuation">;</span>
get <span class="token function">env</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword">import</span><span class="token punctuation">(</span>"@tsed/core"<span class="token punctuation">)</span>.<a href="/api/core/domain/Env.html"><span class="token">Env</span></a><span class="token punctuation">;</span>
get <span class="token function">app</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <a href="/api/common/platform/services/PlatformApplication.html"><span class="token">PlatformApplication</span></a>&lt;TsED.Application<span class="token punctuation">,</span> TsED.Router&gt;<span class="token punctuation">;</span>
<span class="token function">destroy</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> Promise&lt;<span class="token keyword">void</span>&gt;<span class="token punctuation">;</span>
<span class="token function">isDone</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword">boolean</span><span class="token punctuation">;</span>
<span class="token function">emit</span><span class="token punctuation">(</span>eventName<span class="token punctuation">:</span> <span class="token keyword">string</span><span class="token punctuation">,</span> ...args<span class="token punctuation">:</span> <span class="token keyword">any</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">:</span> Promise&lt;<span class="token keyword">void</span>&gt;<span class="token punctuation">;</span>

getRequest&lt;<a href="/api/common/mvc/decorators/params/Req.html"><span class="token">Req</span></a><span class="token punctuation"> = </span><span class="token keyword">any</span>&gt;<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <a href="/api/common/mvc/decorators/params/Req.html"><span class="token">Req</span></a><span class="token punctuation">;</span>

getResponse&lt;<a href="/api/common/mvc/decorators/params/Res.html"><span class="token">Res</span></a><span class="token punctuation"> = </span><span class="token keyword">any</span>&gt;<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <a href="/api/common/mvc/decorators/params/Res.html"><span class="token">Res</span></a><span class="token punctuation">;</span>

<span class="token function">getReq</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> IncomingMessage<span class="token punctuation">;</span>

<span class="token function">getRes</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> ServerResponse<span class="token punctuation">;</span>

getApp&lt;T<span class="token punctuation"> = </span><span class="token keyword">any</span>&gt;<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> T<span class="token punctuation">;</span>

}

# Members

readonly id: string;

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.

@Configuration({
  logger: {
    reqIdBuilder: createUniqId // give your own id generator function
  }
})
class Server {

}
1
2
3
4
5
6
7
8

:::


readonly dateStart: Date;

Date when request have been handled by the server. RequestLogger use this date to log request duration.


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 EndpointMetadata resolved by Ts.ED during the request.


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 PlatformResponse.


request: PlatformRequest;

The current PlatformRequest.


injector: InjectorService;

get env(): import("@tsed/core").Env;

get app(): PlatformApplication<TsED.Application, TsED.Router>;

destroy(): Promise<void>;

isDone(): boolean;

emit(eventName: string, ...args: any[]): Promise<void>;

getRequest<Req = any>(): Req;

Return the framework request instance (Express, Koa, etc...)


getResponse<Res = any>(): Res;

Return the framework response instance (Express, Koa, etc...)


getReq(): IncomingMessage;

Get Node.js request


getRes(): ServerResponse;

Get Node.js response


getApp<T = any>(): T;

Return the original application instance.

Other topics