@loopback/context-explorer
Version:
Visualize context hierarchy, bindings, configurations, and dependencies
39 lines (35 loc) • 1.25 kB
text/typescript
// Copyright IBM Corp. and LoopBack contributors 2020. All Rights Reserved.
// Node module: @loopback/context-explorer
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
import {
Component,
config,
ContextTags,
CoreBindings,
inject,
injectable,
} from '@loopback/core';
import {RestApplication} from '@loopback/rest';
import path from 'path';
import {contextExplorerControllerFactory} from './context-explorer.controller';
import {ContextExplorerBindings} from './keys';
import {ContextExplorerConfig} from './types';
/**
* A component providing a self-hosted API Explorer.
*/
({tags: {[ContextTags.KEY]: ContextExplorerBindings.COMPONENT.key}})
export class ContextExplorerComponent implements Component {
constructor(
(CoreBindings.APPLICATION_INSTANCE)
application: RestApplication,
()
explorerConfig: ContextExplorerConfig = {},
) {
const explorerPath = explorerConfig.path ?? '/context-explorer';
if (explorerConfig.enableD3Animation !== false) {
application.static(explorerPath, path.join(__dirname, '../public'));
}
application.controller(contextExplorerControllerFactory(explorerPath));
}
}