Skip to content

Commit

Permalink
refactor(rest): Index rest config with hash
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Delisle committed Sep 29, 2017
1 parent 6fe6052 commit b0e5360
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 14 deletions.
2 changes: 1 addition & 1 deletion packages/rest/src/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {CoreBindings} from '@loopback/core';

export namespace RestBindings {
// RestServer-specific bindings
export const CONFIG = 'rest.config';
export const CONFIG = `${CoreBindings.APPLICATION_CONFIG}#rest`;
export const PORT = 'rest.port';
export const HANDLER = 'rest.handler';

Expand Down
14 changes: 1 addition & 13 deletions packages/rest/src/rest-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,13 @@ export class RestComponent implements Component {
servers: Constructor<Server>[] = [];
constructor(
@inject(CoreBindings.APPLICATION_INSTANCE) app: Application,
@inject(CoreBindings.APPLICATION_CONFIG, undefined, getRestConfig)
config?: RestComponentConfig,
@inject(RestBindings.CONFIG) config?: RestComponentConfig,
) {
if (!config) config = {};
app.bind(RestBindings.CONFIG).to(config);
this.servers.push(RestServer);
}
}

function getRestConfig(
ctx: Context,
injection: Injection,
): ValueOrPromise<BoundValue> {
// FIXME(kevin): This is a workaround for the hash (#) keyed property
// resolving not working!
const conf = ctx.getSync(injection.bindingKey) as ApplicationConfig;
return conf.rest || {};
}

export interface RestComponentConfig extends RestServerConfig {
// TODO(kevin): Extend this interface def to include multiple servers?
}

0 comments on commit b0e5360

Please sign in to comment.