import { BasePlugin , BaseChannel } from 'lisk-framework' ; import * as express from 'express' ; import { join } from 'path' ; import { Server } from 'http' ; import { configSchema } from './schemas' ; import { DashboardPluginConfig } from './types' ; export class DashboardPlugin extends BasePlugin < DashboardPluginConfig > { public name = 'dashboard' ; public configSchema = configSchema ; private _server ! : Server ; public get nodeModulePath ( ) : string { return __filename ; } public async load ( _channel ) { const config = { applicationUrl : this . config . applicationUrl , applicationName : this . config . applicationName , } ; const app = express ( ) ; app . use ( express . static ( join ( __dirname , '../../build' ) ) ) ; app . get ( '/api/config' , ( _req , res ) => res . json ( config ) ) ; this . _server = app . listen ( this . config . port , this . config . host ) ; } public async unload ( ) { await new Promise < void > ( ( resolve , reject ) => { this . _server . close ( err => { if ( err ) { reject ( err ) ; return ; } resolve ( ) ; } ) ; } ) ; } }