Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Siegrift committed Dec 6, 2023
1 parent e212d8f commit 2a7b65f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
8 changes: 4 additions & 4 deletions packages/airnode-feed/src/validation/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import dotenv from 'dotenv';
import { configSchema } from './schema';
import { interpolateSecrets, parseSecrets } from './utils';

// When Airnode feed is built the "/dist" file contains "src" folder and "package.json" and the config is expected to be
// located next to the "/dist" folder. When run in development, the config is expected to be located next to the "src"
// folder (one less import level). We resolve the config by CWD as a workaround. Since the Airnode feed is dockerized,
// this is hidden from the user.
// When Airnode feed is built, the "/dist" file contains "src" folder and "package.json" and the config is expected to
// be located next to the "/dist" folder. When run in development, the config is expected to be located next to the
// "src" folder (one less import level). We resolve the config by CWD as a workaround. Since the Airnode feed is
// dockerized, this is hidden from the user.
const getConfigPath = () => join(cwd(), './config');

export const loadRawConfig = () => JSON.parse(fs.readFileSync(join(getConfigPath(), 'airnode-feed.json'), 'utf8'));
Expand Down
3 changes: 1 addition & 2 deletions packages/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,7 @@ The API provides the following endpoints:
## Versioning and release

Signed API uses [semantic versioning](https://semver.org/). The version is specified in the `package.json` file. The
package is not published to NPM, but instead dockerized and published to Docker Hub. The image is called
[api3/signed-api](https://hub.docker.com/r/api3/signed-api).
package is not published to NPM, but instead dockerized and published to Docker Hub.

To release a new version:

Expand Down
12 changes: 11 additions & 1 deletion packages/api/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { readFileSync } from 'node:fs';
import { join } from 'node:path';
import { cwd } from 'node:process';

import { go } from '@api3/promise-utils';
import { S3 } from '@aws-sdk/client-s3';
Expand All @@ -22,12 +23,21 @@ export const fetchAndCacheConfig = async (): Promise<Config> => {
return config;
};

// When Signed API is built, the "/dist" file contains "src" folder and "package.json" and the config is expected to be
// located next to the "/dist" folder. When run in development, the config is expected to be located next to the "src"
// folder (one less import level). We resolve the config by CWD as a workaround. Since the Signed API is dockerized,
// this is hidden from the user.
const getConfigPath = () => join(cwd(), './config');

export const loadConfigFromFilesystem = () =>
JSON.parse(readFileSync(join(getConfigPath(), 'signed-api.json'), 'utf8'));

const fetchConfig = async (): Promise<any> => {
const env = loadEnv();
const source = env.CONFIG_SOURCE;
switch (source) {
case 'local': {
return JSON.parse(readFileSync(join(__dirname, '../config/signed-api.json'), 'utf8'));
return loadConfigFromFilesystem();
}
case 'aws-s3': {
return fetchConfigFromS3();
Expand Down

0 comments on commit 2a7b65f

Please sign in to comment.