Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import {Deprecated, ProxyMap, Type} from "@tsed/core";
import {Configuration, Injectable, InjectorService, ProviderScope, ProviderType} from "@tsed/di";
import {ControllerProvider} from "../models/ControllerProvider";
import {ControllerRegistry} from "../registries/ControllerRegistry";
import {IRouteController, RouteService} from "./RouteService";
/**
* @private
* @deprecated
*/
@Injectable({
scope: ProviderScope.SINGLETON,
global: true
})
export class ControllerService extends ProxyMap | any, ControllerProvider> {
constructor(
private injectorService: InjectorService,
@Configuration() private settings: Configuration,
private routeService: RouteService
) {
super(injectorService as any, {filter: {type: ProviderType.CONTROLLER}});
}
/**
* @deprecated
*/
/* istanbul ignore next */
const rootDir = process.cwd();
/**
* @deprecated
*/
export let globalServerSettings: ServerSettingsService;
/**
* @deprecated
*/
// tslint:disable-next-line: variable-name
export let GlobalServerSettings: ServerSettingsService;
/**
* `ServerSettingsService` contains all information about [ServerLoader](/api/common/server/components/ServerLoader.md) configuration.
*/
@Injectable({
scope: ProviderScope.SINGLETON,
global: true
})
export class ServerSettingsService implements IServerSettings, IDISettings {
protected map = new Map();
constructor() {
this.rootDir = rootDir;
this.env = (process.env.NODE_ENV as Env) || Env.DEV;
this.port = 8080;
this.httpsPort = 8000;
this.version = "1.0.0";
this.uploadDir = "${rootDir}/uploads";
this.controllerScope = ProviderScope.SINGLETON;
this.logger = {
debug: false,
level: "info",
constructor() {
this.rootDir = rootDir;
this.env = (process.env.NODE_ENV as Env) || Env.DEV;
this.port = 8080;
this.httpsPort = 8000;
this.version = "1.0.0";
this.uploadDir = "${rootDir}/uploads";
this.controllerScope = ProviderScope.SINGLETON;
this.logger = {
debug: false,
level: "info",
logRequest: true,
jsonIndentation: this.env === Env.PROD ? 0 : 2
};
this.errors = {
headerName: "errors"
};
this.mount = {
"/rest": "${rootDir}/controllers/**/*.ts"
};
this.exclude = ["**/*.spec.ts", "**/*.spec.js"];
import {InjectorService, ProviderScope, registerProvider} from "@tsed/di";
import * as Https from "https";
import {ServerSettingsService} from "../../config";
import {ExpressApplication} from "../decorators/expressApplication";
import {HttpsServer} from "../decorators/httpsServer";
export function createHttpsServer(injector: InjectorService): void {
injector.forkProvider(HttpsServer);
}
registerProvider({
provide: HttpsServer,
deps: [ExpressApplication, ServerSettingsService],
scope: ProviderScope.SINGLETON,
global: true,
useFactory(expressApplication: ExpressApplication, settings: ServerSettingsService) {
const options = settings.httpsOptions;
return Https.createServer(options, expressApplication);
}
});
import {InjectorService, ProviderScope, registerProvider} from "@tsed/di";
import * as Http from "http";
import {ExpressApplication} from "../decorators/expressApplication";
import {HttpServer} from "../decorators/httpServer";
export function createHttpServer(injector: InjectorService): void {
injector.forkProvider(HttpServer);
}
registerProvider({
provide: HttpServer,
deps: [ExpressApplication],
scope: ProviderScope.SINGLETON,
global: true,
useFactory(expressApplication: ExpressApplication) {
return Http.createServer(expressApplication);
}
});
import {InjectorService, ProviderScope, registerProvider} from "@tsed/di";
import * as Express from "express";
import {HandlerBuilder} from "../../mvc";
import {ExpressApplication} from "../decorators/expressApplication";
export function createExpressApplication(injector: InjectorService): void {
injector.forkProvider(ExpressApplication);
}
registerProvider({
provide: ExpressApplication,
deps: [InjectorService],
scope: ProviderScope.SINGLETON,
global: true,
useFactory(injector: InjectorService) {
const expressApp = Express();
const originalUse = expressApp.use;
expressApp.use = function(...args: any[]) {
args = args.map(arg => {
if (injector.has(arg)) {
arg = HandlerBuilder.from(arg).build(injector);
}
return arg;
});
return originalUse.call(this, ...args);
};