import Path from 'path' ; import { fromRoot } from '../../../core/server/utils' ; import { InternalCoreSetup } from '../internal_types' ; import { CoreContext } from '../core_context' ; import { Logger } from '../logging' ; internal export class CoreApp { private readonly logger : Logger ; constructor ( core ) { this . logger = core . logger . get ( 'core-app' ) ; } setup ( coreSetup ) { this . logger . debug ( 'Setting up core app.' ) ; this . registerDefaultRoutes ( coreSetup ) ; this . registerStaticDirs ( coreSetup ) ; } private registerDefaultRoutes ( coreSetup ) { const httpSetup = coreSetup . http ; const router = httpSetup . createRouter ( '/' ) ; router . get ( { path : '/' , validate : false } , async ( context , req , res ) => { let defaultRoute = await context . core . uiSettings . client . get < string > ( 'defaultRoute' ) ; defaultRoute = defaultRoute . replace ( 'kibana_overview' , 'opensearch_dashboards_overview' ) ; const basePath = httpSetup . basePath . get ( req ) ; const url = `${ basePath }${ defaultRoute }` ; return res . redirected ( { headers : { location : url , } , } ) ; } ) ; router . get ( { path : '/core' , validate : false } , async ( context , req , res ) => res . ok ( { body : { version : '0.0.1' } } ) ) ; const anonymousStatusPage = coreSetup . status . isStatusPageAnonymous ( ) ; coreSetup . httpResources . createRegistrar ( router ) . register ( { path : '/status' , validate : false , options : { authRequired : ! anonymousStatusPage , } , } , async ( context , request , response ) => { if ( anonymousStatusPage ) { return response . renderAnonymousCoreApp ( ) ; } else { return response . renderCoreApp ( ) ; } } ) ; } private registerStaticDirs ( coreSetup ) { coreSetup . http . registerStaticDir ( '/ui/{path*}' , Path . resolve ( __dirname , './assets' ) ) ; coreSetup . http . registerStaticDir ( '/node_modules/@osd/ui-framework/dist/{path*}' , fromRoot ( 'node_modules/@osd/ui-framework/dist' ) ) ; } }