Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion library/html-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ class HtmlServer {
.replace(/\[%total-packages%\]/g, escape(renderOptions.totalPackages.toLocaleString()))
.replace(/\[%endpoint-path%\]/g, escape(renderOptions.endpointpath))
.replace(/\[%fhir-version%\]/g, escape(renderOptions.fhirversion))
.replace(/\[%ms%\]/g, escape(renderOptions.processingTime.toString()));
.replace(/\[%ms%\]/g, escape(renderOptions.processingTime.toString()))
.replace(/\[%about%\]/g, renderOptions.about || '');

// Handle any custom template variables
if (options.templateVars) {
Expand Down
1 change: 1 addition & 0 deletions root-template.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ <h2><img border="0" src="/FHIRsmith32.png" style="vertical-align: text-bottom"/>

[%content%]

[%about%]

</div>

Expand Down
12 changes: 10 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,12 +382,20 @@ app.get('/', async (req, res) => {
}

const content = await buildRootPageContent();


// Load optional about box fragment from data directory
let about = '';
const aboutPath = path.join(folders.dataDir(), 'about.html');
if (fs.existsSync(aboutPath)) {
about = fs.readFileSync(aboutPath, 'utf8');
}

// Build basic stats for root page
const stats = {
version: packageJson.version,
enabledModules: Object.keys(config.modules).filter(m => config.modules[m].enabled).length,
processingTime: Date.now() - startTime
processingTime: Date.now() - startTime,
about
};

const html = htmlServer.renderPage('root', escape(config.hostName) || 'FHIRsmith Server', content, stats);
Expand Down
59 changes: 59 additions & 0 deletions tests/server/about-box.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
const path = require('path');
const fs = require('fs');
const tmp = require('tmp');

const HtmlServer = require('../../library/html-server').constructor;

describe('About box', () => {
let htmlServer;
let tmpDir;

beforeAll(() => {
tmpDir = tmp.dirSync({ unsafeCleanup: true });
htmlServer = new HtmlServer();
htmlServer.useLog({ error: jest.fn(), warn: jest.fn() });

// Load root template
const templatePath = path.join(__dirname, '../../root-template.html');
htmlServer.loadTemplate('root', templatePath);
});

afterAll(() => {
tmpDir.removeCallback();
});

test('renders about content when provided', () => {
const aboutHtml = '<div class="about">Custom About Content</div>';
const html = htmlServer.renderPage('root', 'Test', '<p>Main</p>', {
version: '1.0.0',
processingTime: 0,
about: aboutHtml
});
expect(html).toContain('Custom About Content');
expect(html).toContain('<div class="about">');
});

test('renders empty when about is not provided', () => {
const html = htmlServer.renderPage('root', 'Test', '<p>Main</p>', {
version: '1.0.0',
processingTime: 0
});
expect(html).not.toContain('[%about%]');
});

test('about.html is loaded from data directory when it exists', () => {
const aboutContent = '<p>Server operated by Acme Corp</p>';
fs.writeFileSync(path.join(tmpDir.name, 'about.html'), aboutContent);

const aboutPath = path.join(tmpDir.name, 'about.html');
expect(fs.existsSync(aboutPath)).toBe(true);

const loaded = fs.readFileSync(aboutPath, 'utf8');
expect(loaded).toBe(aboutContent);
});

test('missing about.html does not cause errors', () => {
const aboutPath = path.join(tmpDir.name, 'nonexistent', 'about.html');
expect(fs.existsSync(aboutPath)).toBe(false);
});
});
Loading