From 97ca88bf0c48aa07fbe6c1048cbd1d19013ae8a0 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Tue, 3 Dec 2024 15:42:07 +0100 Subject: [PATCH] Inject configuration dependency --- src/collection-api/routes/index.js | 6 +++++- src/collection-api/routes/metadata.js | 5 ++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/collection-api/routes/index.js b/src/collection-api/routes/index.js index 630291d1..4585c7e2 100644 --- a/src/collection-api/routes/index.js +++ b/src/collection-api/routes/index.js @@ -1,3 +1,6 @@ +import path from 'path'; + +import config from 'config'; import express from 'express'; import helmet from 'helmet'; @@ -30,9 +33,10 @@ export default async function apiRouter(basePath) { res.json({ message: 'Welcome to an instance of the Open Terms Archive API. Documentation is available at /docs. Learn more on Open Terms Archive on https://opentermsarchive.org.' }); }); + const collectionPath = path.resolve(process.cwd(), config.get('@opentermsarchive/engine.collectionPath')); const services = await Services.load(); - router.use(await metadataRouter(services)); + router.use(await metadataRouter(collectionPath, services)); router.use(servicesRouter(services)); router.use(versionsRouter); diff --git a/src/collection-api/routes/metadata.js b/src/collection-api/routes/metadata.js index f42bf562..27c28221 100644 --- a/src/collection-api/routes/metadata.js +++ b/src/collection-api/routes/metadata.js @@ -1,7 +1,6 @@ import fs from 'fs/promises'; import path from 'path'; -import config from 'config'; import express from 'express'; import yaml from 'js-yaml'; @@ -128,9 +127,9 @@ import Service from '../../archivist/services/service.js'; * format: uri * description: URL to the organization's logo */ -export default async function metadataRouter(services) { +export default async function metadataRouter(collectionPath, services) { const router = express.Router(); - const collectionPath = path.resolve(process.cwd(), config.get('@opentermsarchive/engine.collectionPath')); + const STATIC_METADATA = yaml.load(await fs.readFile(path.join(collectionPath, '/metadata.yml'), 'utf8')); const { version: engineVersion } = JSON.parse(await fs.readFile(new URL('../../../package.json', import.meta.url)));