import * as fs from 'fs'; import * as path from 'path'; import {RestBindings, Response, get} from '@loopback/rest'; import {authorize} from 'loopback4-authorization'; import {STATUS_CODE} from '@sourcefuse-npm/alivio-lib'; import {inject} from '@loopback/core'; export class HomePageController { private readonly html: string; constructor( @inject(RestBindings.Http.RESPONSE) private readonly response: Response, ) { this.html = fs.readFileSync( path.join(__dirname, '../../public/index.html'), 'utf-8', ); // Replace base path placeholder from env this.html = this.html.replace( /\$\{basePath\}/g, process.env.BASE_PATH ?? '', ); } @authorize({permissions: ['*']}) @get('/', { responses: { 200: { description: 'Home Page', content: {'text/html': {schema: {type: 'string'}}}, }, }, }) homePage() { this.response.status(STATUS_CODE.OK).contentType('html').send(this.html); return this.response; } }