Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1052 from calimero-is-near/use_middleware_to_set_…
Browse files Browse the repository at this point in the history
…apkikey

fix: move x-api-key logic to middlewares
  • Loading branch information
ailisp authored Mar 9, 2023
2 parents 1a8a5a0 + 394cc9c commit 4649d5e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
1 change: 1 addition & 0 deletions bin/near-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ yargs // eslint-disable-line
.middleware(require('../middleware/ledger'))
.middleware(require('../middleware/abi'))
.middleware(require('../middleware/seed-phrase'))
.middleware(require('../middleware/x-api-key'))
.command(require('../commands/create-account').createAccountCommand)
.command(require('../commands/create-account').createAccountCommandDeprecated)
.command(viewAccount)
Expand Down
8 changes: 0 additions & 8 deletions config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const { getXApiKey } = require('./utils/x-api-key-settings.js');

const CONTRACT_NAME = process.env.CONTRACT_NAME;

function getConfig(env) {
Expand Down Expand Up @@ -86,12 +84,6 @@ function getConfig(env) {
default:
throw Error(`Unconfigured environment '${env}'. Can be configured in src/config.js.`);
}

// adding x-api-key for given RPC Server
const apiKey = getXApiKey(config.nodeUrl);
if (apiKey) {
config.headers = { 'x-api-key': apiKey };
}
return config;
}

Expand Down
9 changes: 9 additions & 0 deletions middleware/x-api-key.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const { getXApiKey } = require('../utils/x-api-key-settings');

module.exports = async function setNodeXApiKey(options) {
const apiKey = getXApiKey(options.nodeUrl);
if (apiKey) {
options.headers = { 'x-api-key': apiKey };
}
return options;
};

0 comments on commit 4649d5e

Please sign in to comment.