# PlatformBuilder Class platform
Module | import { PlatformBuilder } from "@tsed/common" |
---|---|
Source | /packages/common/src/platform-builder/builder/PlatformBuilder.ts |
# Overview
abstract class PlatformBuilder {
protected startedAt: Date;
protected _rootModule: any;
protected _injector: InjectorService;
get injector(): InjectorService;
get rootModule(): any;
get app(): PlatformApplication;
get platform(): Platform;
/**
* Return the settings configured by the decorator @@Configuration@@.
*
* ```typescript
* @Configuration({
* rootDir: Path.resolve(__dirname),
* port: 8000,
* httpsPort: 8080,
* mount: {
* "/rest": "${rootDir}/controllers/**\/*.js"
* }
* })
* export class Server {
* $onInit(){
* console.log(this.settings); // {rootDir, port, httpsPort,...}
* }
* }
* ```
*
* @returns {ServerSettingsService}
*/
get settings(): TsED.Configuration & import("@tsed/di").DIConfiguration;
get logger(): import("@tsed/di").IDILogger;
static build<T extends PlatformBuilder>(platformBuildClass: Type<T>): T;
/**
* Add classes to the components list
* @param classes
*/
addComponents(classes: any | any[]): this;
/**
* Add classes decorated by @@Controller@@ to components container.
*
* ### Example
*
* ```typescript
* @Controller('/ctrl')
* class MyController{
* }
*
* platform.addControllers('/rest', [MyController])
* ```
*
* ::: tip
* If the MyController class isn't decorated, the class will be ignored.
* :::
*
* @param {string} endpoint
* @param {any[]} controllers
*/
addControllers(endpoint: string, controllers: any | string | (any | string)[]): void;
runLifecycle(): Promise<void>;
loadInjector(): Promise<void>;
listen(): Promise<void>;
ready(): Promise<void>;
callHook(key: string, ...args: any[]): Promise<void>;
loadStatics(): Promise<void>;
protected bootstrap(module: Type<any>, settings?: Partial<TsED.Configuration>): Promise<this>;
protected listenServers(): Promise<void>;
protected logRoutes(): void;
protected createContext(): Promise<PlatformApplication<TsED.Application>>;
protected loadRoutes(routes: IRoute[]): Promise<void>;
protected createInjector(module: Type<any>, settings: any): void;
protected createRootModule(module: Type<any>): void;
}
# Members
protected startedAt: Date;
protected _rootModule: any;
protected _injector: InjectorService;
get injector(): InjectorService;
get rootModule(): any;
get app(): PlatformApplication;
get platform(): Platform;
get settings(): TsED.Configuration & import("@tsed/di").DIConfiguration;
Return the settings configured by the decorator
@Configuration({
rootDir: Path.resolve(__dirname),
port: 8000,
httpsPort: 8080,
mount: {
"/rest": "${rootDir}/controllers/**/*.js"
}
})
export class Server {
$onInit(){
console.log(this.settings); // {rootDir, port, httpsPort,...}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
get logger(): import("@tsed/di").IDILogger;
static build<T extends PlatformBuilder>(platformBuildClass: Type<T>): T;
addComponents(classes: any | any[]): this;
Add classes to the components list
addControllers(endpoint: string, controllers: any | string | (any | string)[]): void;
Add classes decorated by
# Example
@Controller('/ctrl')
class MyController{
}
platform.addControllers('/rest', [MyController])
1
2
3
4
5
2
3
4
5
TIP
If the MyController class isn't decorated, the class will be ignored.
:::
runLifecycle(): Promise<void>;
loadInjector(): Promise<void>;
listen(): Promise<void>;
ready(): Promise<void>;
callHook(key: string, ...args: any[]): Promise<void>;
loadStatics(): Promise<void>;
protected bootstrap(module: Type<any>, settings?: Partial<TsED.Configuration>): Promise<this>;
protected listenServers(): Promise<void>;
protected logRoutes(): void;
protected createContext(): Promise<PlatformApplication<TsED.Application>>;
protected loadRoutes(routes: IRoute[]): Promise<void>;
protected createInjector(module: Type<any>, settings: any): void;
protected createRootModule(module: Type<any>): void;
- 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