Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Ndpnt committed Apr 18, 2024
1 parent 7c5adf2 commit 5998fac
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion config/default.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"opentermsarchive/federated-api": {
"@opentermsarchive/federated-api": {
"collectionsUrl": "https://opentermsarchive.org/collections.json",
"logger": {
"smtp": {
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ if (process.env.NODE_ENV !== 'test') {
app.use(loggerMiddleware);
}

export const BASE_PATH = path.join('/', config.get('opentermsarchive/federated-api.basePath'), 'v1');
export const BASE_PATH = path.join('/', config.get('@opentermsarchive/federated-api.basePath'), 'v1');

app.use(BASE_PATH, apiRouter(BASE_PATH));
app.use(errorsMiddleware);

const PORT = config.get('opentermsarchive/federated-api.port');
const PORT = config.get('@opentermsarchive/federated-api.port');

app.listen(PORT, () => {
logger.info(`Start Open Terms Archive Federation API on http://localhost:${PORT}${BASE_PATH}`);
Expand Down
2 changes: 1 addition & 1 deletion src/routes/collections.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const COLLECTIONS_RESULT = {

describe('Collections routes', () => {
before(() => {
nock(config.get('opentermsarchive/federated-api.collectionsUrl')).persist().get('').reply(200, COLLECTIONS_RESULT);
nock(config.get('@opentermsarchive/federated-api.collectionsUrl')).persist().get('').reply(200, COLLECTIONS_RESULT);
});

after(() => {
Expand Down
4 changes: 2 additions & 2 deletions src/routes/services.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe('Services routes', () => {
const serviceWithUrlEncodedChineseCharactersName = '%E6%8A%96%E9%9F%B3%E7%9F%AD%E8%A7%86%E9%A2%91';

before(() => {
nock(config.get('opentermsarchive/federated-api.collectionsUrl')).persist().get('').reply(200, COLLECTIONS_RESULT);
nock(config.get('@opentermsarchive/federated-api.collectionsUrl')).persist().get('').reply(200, COLLECTIONS_RESULT);
nock('http://collection-1.example').persist().get('/api/v1/services').reply(200, COLLECTION_1_SERVICES_RESULT);
nock('https://2.collection.example').persist().get('/api/v1/services').reply(200, COLLECTION_2_SERVICES_RESULT);
});
Expand Down Expand Up @@ -267,7 +267,7 @@ describe('Services routes', () => {
context('when an error occurs in one of the underlying collections', () => {
before(async () => {
nock.cleanAll();
nock(config.get('opentermsarchive/federated-api.collectionsUrl')).persist().get('').reply(200, COLLECTIONS_RESULT);
nock(config.get('@opentermsarchive/federated-api.collectionsUrl')).persist().get('').reply(200, COLLECTIONS_RESULT);
nock('http://collection-1.example').persist().get('/api/v1/services').reply(200, COLLECTION_1_SERVICES_RESULT);
nock('https://2.collection.example').get('/api/v1/services').replyWithError({
message: 'something went wrong',
Expand Down
2 changes: 1 addition & 1 deletion src/services/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import config from 'config';
import fetch from '../utils/fetch.js';

export const fetchCollections = async () => {
const collections = await fetch(config.get('opentermsarchive/federated-api.collectionsUrl'));
const collections = await fetch(config.get('@opentermsarchive/federated-api.collectionsUrl'));

return Object.keys(collections).reduce((result, collectionName) => {
if (collections[collectionName].endpoint) {
Expand Down
10 changes: 5 additions & 5 deletions src/utils/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ const logger = winston.createLogger({
rejectionHandlers: transports,
});

if (config.get('opentermsarchive/federated-api.logger.sendMailOnError')) {
if (config.get('@opentermsarchive/federated-api.logger.sendMailOnError')) {
if (process.env.SMTP_PASSWORD === undefined) {
logger.warn('Environment variable "SMTP_PASSWORD" was not found; log emails cannot be sent');
} else {
transports.push(new winston.transports.Mail({
to: config.get('opentermsarchive/federated-api.logger.sendMailOnError.to'),
from: config.get('opentermsarchive/federated-api.logger.sendMailOnError.from'),
host: config.get('opentermsarchive/federated-api.logger.smtp.host'),
username: config.get('opentermsarchive/federated-api.logger.smtp.username'),
to: config.get('@opentermsarchive/federated-api.logger.sendMailOnError.to'),
from: config.get('@opentermsarchive/federated-api.logger.sendMailOnError.from'),
host: config.get('@opentermsarchive/federated-api.logger.smtp.host'),
username: config.get('@opentermsarchive/federated-api.logger.smtp.username'),
password: process.env.SMTP_PASSWORD,
ssl: true,
timeout: 30 * 1000,
Expand Down

0 comments on commit 5998fac

Please sign in to comment.