Skip to content

Commit 3d27388

Browse files
committed
fix(common): Fix problem with port configuration
Closes: #632
1 parent 89d5166 commit 3d27388

File tree

5 files changed

+19
-18
lines changed

5 files changed

+19
-18
lines changed

integration/getting-started/src/Server.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ const compress = require("compression");
88
const methodOverride = require("method-override");
99
const rootDir = __dirname;
1010

11-
const config: IServerSettings = {
12-
swagger: {}
13-
};
14-
1511
@ServerSettings({
1612
rootDir,
1713
acceptMimes: ["application/json"],
@@ -28,9 +24,7 @@ const config: IServerSettings = {
2824
},
2925
calendar: {
3026
token: true
31-
},
32-
debug: true,
33-
swagger: {}
27+
}
3428
})
3529
export class Server extends ServerLoader {
3630
constructor(settings) {

packages/common/src/config/services/ServerSettingsService.ts

+4
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ export class ServerSettingsService extends DIConfiguration {
5858
this.map.set("rootDir", value);
5959
}
6060

61+
get port(): string | number {
62+
return this.httpPort;
63+
}
64+
6165
set port(value: string | number) {
6266
this.httpPort = value;
6367
}

packages/common/src/server/decorators/serverSettings.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {StoreSet} from "@tsed/core";
2-
import {IServerSettings} from "../../config/interfaces/IServerSettings";
2+
import {IDIConfigurationOptions} from "@tsed/di";
33

44
/**
55
* `@ServerSettings` let you to configure quickly your server via decorator. This decorator take your configuration and merge it with the default server configuration.
@@ -49,6 +49,6 @@ import {IServerSettings} from "../../config/interfaces/IServerSettings";
4949
* @returns {(target:any)=>any}
5050
* @decorator
5151
*/
52-
export function ServerSettings(settings: Partial<IServerSettings>): Function {
52+
export function ServerSettings(settings: Partial<IDIConfigurationOptions>): Function {
5353
return StoreSet("PLATFORM_SETTINGS", settings);
5454
}

packages/common/test/config/services/ServerSettingsService.spec.ts

+11
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,17 @@ describe("ServerSettingsService", () => {
178178
});
179179
});
180180

181+
describe("port", () => {
182+
it("should set port", () => {
183+
const settings = new ServerSettingsService();
184+
185+
settings.set({port: 8081});
186+
187+
expect(settings.httpPort).to.eq(8081);
188+
expect(settings.port).to.eq(8081);
189+
});
190+
});
191+
181192
describe("resolve()", () => {
182193
it("should replace rootDir", () => {
183194
expect(settings.resolve("${rootDir}")).to.eq(process.cwd());

packages/di/src/services/DIConfiguration.ts

+1-9
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,7 @@ export class DIConfiguration {
8282
if (typeof propertyKey === "string") {
8383
setValue(propertyKey, value, this.map);
8484
} else {
85-
Object.entries(propertyKey).forEach(([key, value]) => {
86-
const descriptor = Object.getOwnPropertyDescriptor(DIConfiguration.prototype, key);
87-
88-
if (descriptor && ["set", "map", "get"].indexOf(key) === -1) {
89-
this[key] = value;
90-
} else {
91-
this.set(key, value);
92-
}
93-
});
85+
Object.assign(this, propertyKey);
9486
}
9587

9688
return this;

0 commit comments

Comments
 (0)