@tsed/platform-http
Version:
A TypeScript Framework on top of Express
119 lines (118 loc) • 3.24 kB
JavaScript
import { __decorate, __metadata } from "tslib";
import { getHostInfoFromPort, isBoolean } from "@tsed/core";
import { DIConfiguration, Injectable, ProviderScope } from "@tsed/di";
import { JsonMapperSettings } from "@tsed/json-mapper";
const rootDir = process.cwd();
/**
* `PlatformConfiguration` contains all information about your Server configuration.
*/
let PlatformConfiguration = class PlatformConfiguration extends DIConfiguration {
constructor() {
super({ rootDir });
}
get port() {
return this.httpPort;
}
set port(value) {
this.httpPort = value;
}
get httpsOptions() {
return this.getRaw("httpsOptions");
}
set httpsOptions(value) {
this.setRaw("httpsOptions", value);
}
get httpPort() {
return this.getRaw("httpPort");
}
set httpPort(value) {
this.setRaw("httpPort", value);
}
get httpsPort() {
return this.getRaw("httpsPort");
}
set httpsPort(value) {
this.setRaw("httpsPort", value);
}
get mount() {
return this.get("mount");
}
set mount(value) {
this.setRaw("mount", value);
}
get statics() {
return this.getRaw("statics") || this.getRaw("serveStatic") || {};
}
set statics(value) {
this.setRaw("statics", value);
}
get acceptMimes() {
return this.getRaw("acceptMimes");
}
set acceptMimes(value) {
this.setRaw("acceptMimes", value || []);
}
get jsonMapper() {
return {
...JsonMapperSettings
};
}
set jsonMapper(options) {
JsonMapperSettings.strictGroups = Boolean(options.strictGroups);
JsonMapperSettings.disableUnsecureConstructor = Boolean(options.disableUnsecureConstructor);
JsonMapperSettings.additionalProperties = Boolean(isBoolean(options.additionalProperties) ? options.additionalProperties : options.additionalProperties === "accept");
}
get additionalProperties() {
return this.get("converter.additionalProperties") === "accept";
}
/**
*
* @returns {string|number}
*/
getHttpPort() {
return getHostInfoFromPort("http", this.getRaw("httpPort"));
}
/**
*
* @param settings
*/
setHttpPort(settings) {
this.setRaw("httpPort", `${settings.address}:${settings.port}`);
}
/**
*
* @returns {string|number}
*/
getHttpsPort() {
return getHostInfoFromPort("https", this.getRaw("httpsPort"));
}
/**
*
* @param settings
*/
setHttpsPort(settings) {
this.setRaw("httpsPort", `${settings.address}:${settings.port}`);
}
getBestHost() {
const { httpsPort, httpPort } = this;
if (httpsPort) {
return this.getHttpsPort();
}
if (httpPort) {
return this.getHttpPort();
}
return {
toString() {
return "/";
}
};
}
};
PlatformConfiguration = __decorate([
Injectable({
scope: ProviderScope.SINGLETON,
global: true
}),
__metadata("design:paramtypes", [])
], PlatformConfiguration);
export { PlatformConfiguration };