Skip to content

Commit

Permalink
Inject configuration dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
Ndpnt committed Dec 3, 2024
1 parent c577381 commit 97ca88b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/collection-api/routes/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import path from 'path';

import config from 'config';
import express from 'express';
import helmet from 'helmet';

Expand Down Expand Up @@ -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);

Expand Down
5 changes: 2 additions & 3 deletions src/collection-api/routes/metadata.js
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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)));

Expand Down

0 comments on commit 97ca88b

Please sign in to comment.