Skip to content

Commit d2f1aeb

Browse files
authored
Merge pull request #32 from Johnaverse/copilot/sub-pr-31
Source API version from package.json and validate infoURL protocol
2 parents 9a162e2 + 5101317 commit d2f1aeb

4 files changed

Lines changed: 21 additions & 11 deletions

File tree

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import rateLimit from '@fastify/rate-limit';
44
import helmet from '@fastify/helmet';
55
import { readFile } from 'node:fs/promises';
66
import { basename, resolve } from 'node:path';
7+
import pkg from './package.json' with { type: 'json' };
78
import { loadData, initializeDataOnStartup, getCachedData, searchChains, getChainById, getAllChains, getAllRelations, getRelationsById, getEndpointsById, getAllEndpoints, getAllKeywords, validateChainData, traverseRelations } from './dataService.js';
89
import { getMonitoringResults, getMonitoringStatus, startRpcHealthCheck } from './rpcMonitor.js';
910
import {
@@ -447,7 +448,7 @@ export async function buildApp(options = {}) {
447448
fastify.get('/', async (request, reply) => {
448449
return {
449450
name: 'Chains API',
450-
version: '1.0.0',
451+
version: pkg.version,
451452
description: 'API query service for blockchain chain data from multiple sources',
452453
endpoints: {
453454
'/health': 'Health check and data status',

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/app.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -588,14 +588,23 @@ function showWebsite(data) {
588588
return;
589589
}
590590
try {
591-
const a = document.createElement('a');
592-
a.href = data.infoURL;
593-
a.target = "_blank";
594-
a.rel = "noopener";
595-
a.textContent = new URL(data.infoURL).hostname;
596-
webElem.textContent = '';
597-
webElem.appendChild(a);
591+
const url = new URL(data.infoURL);
592+
const protocol = url.protocol;
593+
594+
if (protocol === 'http:' || protocol === 'https:') {
595+
const a = document.createElement('a');
596+
a.href = url.toString();
597+
a.target = "_blank";
598+
a.rel = "noopener";
599+
a.textContent = url.hostname;
600+
webElem.textContent = '';
601+
webElem.appendChild(a);
602+
} else {
603+
// Unsafe or unsupported protocol: show as plain text without a link
604+
webElem.textContent = data.infoURL;
605+
}
598606
} catch {
607+
// Invalid URL: show as plain text without a link
599608
webElem.textContent = data.infoURL;
600609
}
601610
}

tests/integration/api.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ describe('API Endpoints', () => {
295295
expect(response.statusCode).toBe(200);
296296
const data = JSON.parse(response.payload);
297297
expect(data).toHaveProperty('name', 'Chains API');
298-
expect(data).toHaveProperty('version', '1.0.0');
298+
expect(data).toHaveProperty('version', '1.1.0');
299299
expect(data).toHaveProperty('description');
300300
expect(data).toHaveProperty('endpoints');
301301
expect(data).toHaveProperty('dataSources');

0 commit comments

Comments
 (0)