diff --git a/x-pack/plugins/integration_assistant/server/routes/register_routes.ts b/x-pack/plugins/integration_assistant/server/routes/register_routes.ts index a8ccc39ff2a0f..94efbaa3185de 100644 --- a/x-pack/plugins/integration_assistant/server/routes/register_routes.ts +++ b/x-pack/plugins/integration_assistant/server/routes/register_routes.ts @@ -5,7 +5,11 @@ * 2.0. */ +import { schema } from '@kbn/config-schema'; import type { IRouter } from '@kbn/core/server'; +import fs from 'fs'; +import nunjucks from 'nunjucks'; +import { resolve as resolvePath } from 'path'; import { registerEcsRoutes } from './ecs_routes'; import { registerIntegrationBuilderRoutes } from './build_integration_routes'; import { registerCategorizationRoutes } from './categorization_routes'; @@ -19,4 +23,46 @@ export function registerRoutes(router: IRouter { + let body: Record = {}; + try { + const templateDir = resolvePath(__dirname, '../templates'); + const templateFile = resolvePath(templateDir, 'readme.md.njk'); + body = { + templateDir: { path: templateFile, content: fs.readFileSync(templateFile).toString() }, + }; + + nunjucks.configure([templateDir], { + autoescape: false, + }); + + const readmeTemplate = nunjucks.render('readme.md.njk', { + package_name: 'testPackageName', + data_streams: ['testDataStreamName'], + }); + + body.readme = readmeTemplate; + + return res.ok({ body }); + } catch (error) { + body.error = error.toString(); + return res.customError({ statusCode: 400, body: JSON.stringify(body) }); + } + } + ); }