Skip to content

Commit 866953a

Browse files
author
Kevin Delisle
committed
refactor(core): Component servers are now key-value pairs
BREAKING CHANGE: Components must now provide key-value pairs in an object called "servers".
1 parent b0e5360 commit 866953a

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

packages/core/src/component.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ export interface Component {
1414
// tslint:disable-next-line:no-any
1515
controllers?: Constructor<any>[];
1616
providers?: ProviderMap;
17-
servers?: Constructor<Server>[];
17+
servers?: {
18+
[name: string]: Constructor<Server>;
19+
};
1820

1921
// tslint:disable-next-line:no-any
2022
[prop: string]: any;
@@ -41,8 +43,8 @@ export function mountComponent(app: Application, component: Component) {
4143
}
4244

4345
if (component.servers) {
44-
for (const server of component.servers) {
45-
app.server(server);
46+
for (const serverKey in component.servers) {
47+
app.server(component.servers[serverKey], serverKey);
4648
}
4749
}
4850
}

packages/core/test/unit/application.test.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,14 @@ describe('Application', () => {
6565
});
6666

6767
class FakeComponent implements Component {
68-
servers: Constructor<Server>[] = [];
68+
servers: {
69+
[name: string]: Constructor<Server>;
70+
};
6971
constructor() {
70-
this.servers.push(FakeServer);
72+
this.servers = {
73+
FakeServer,
74+
FakeServer2: FakeServer,
75+
};
7176
}
7277
}
7378

packages/rest/src/rest-component.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,18 @@ export class RestComponent implements Component {
4343
[RestBindings.SequenceActions.PARSE_PARAMS]: ParseParamsProvider,
4444
[RestBindings.SequenceActions.SEND]: SendProvider,
4545
};
46-
servers: Constructor<Server>[] = [];
46+
servers: {
47+
[name: string]: Constructor<Server>;
48+
};
49+
4750
constructor(
4851
@inject(CoreBindings.APPLICATION_INSTANCE) app: Application,
4952
@inject(RestBindings.CONFIG) config?: RestComponentConfig,
5053
) {
5154
if (!config) config = {};
52-
this.servers.push(RestServer);
55+
this.servers = {
56+
RestServer: RestServer,
57+
};
5358
}
5459
}
5560

0 commit comments

Comments
 (0)