How to use the @tsed/di.Constant function in @tsed/di

To help you get started, we’ve selected a few @tsed/di examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TypedProject / ts-express-decorators / packages / seq / src / SeqModule.ts View on Github external
import {AfterRoutesInit} from "@tsed/common";
import {Constant, Module} from "@tsed/di";
import {$log} from "ts-log-debug";
import {ISeqSettings} from "./interfaces/ISeqSettings";

@Module()
export class SeqModule implements AfterRoutesInit {
  @Constant("seq", {
    url: "http://localhost:5341"
  })
  private config: ISeqSettings;

  $afterRoutesInit() {
    $log.appenders.set("seq", {
      type: "seq",
      levels: ["info", "debug", "trace", "fatal", "error", "warn"],
      url: this.config.url,
      apiKey: this.config.apiKey
    });
  }
}
github TypedProject / ts-express-decorators / packages / common / src / server / components / GlobalErrorHandlerMiddleware.ts View on Github external
import {Constant} from "@tsed/di";
import * as Express from "express";
import {Exception} from "ts-httpexceptions";
import {Err, IMiddlewareError, IResponseError, Middleware, Req, Res} from "../../mvc";

/**
 * @middleware
 */
@Middleware()
export class GlobalErrorHandlerMiddleware implements IMiddlewareError {
  @Constant("errors.headerName", "errors")
  protected headerName: string;

  use(@Err() error: any, @Req() request: Req, @Res() response: Res): any {
    const toHTML = (message = "") =&gt; message.replace(/\n/gi, "<br>");

    if (error instanceof Exception || error.status) {
      request.log.error({
        error: {
          message: error.message,
          stack: error.stack,
          status: error.status,
          origin: error.origin
        }
      });

      this.setHeaders(response, error, error.origin);
github TypedProject / ts-express-decorators / packages / common / src / mvc / services / RouteService.ts View on Github external
import {$log} from "ts-log-debug";
import {colorize} from "ts-log-debug/lib/layouts/utils/colorizeUtils";
import {AfterRoutesInit} from "../../server/interfaces/AfterRoutesInit";
import {ControllerProvider} from "../class/ControllerProvider";
import {EndpointMetadata} from "../class/EndpointMetadata";
import {IControllerRoute} from "../interfaces";

/**
 * `RouteService` is used to provide all routes collected by annotation `@Controller`.
 */
@Service()
export class RouteService implements AfterRoutesInit {
  /**
   *
   */
  @Constant("logger.disableRoutesSummary", false)
  disableRoutesSummary: boolean;

  private readonly _routes: {route: string; provider: any}[] = [];

  constructor(private injector: InjectorService) {}

  /**
   *
   * @returns {{route: string; provider: any}[]}
   */
  get routes(): {route: string; provider: any}[] {
    return this._routes || [];
  }

  /**
   *