feathersjs / feathers

The API and real-time application framework
https://feathersjs.com
MIT License
15.06k stars 752 forks source link

Async Configuration Values #2428

Closed Ryan8765 closed 3 years ago

Ryan8765 commented 3 years ago

I'm trying to obtain async configurations for my application (I need to make calls to Amazon Secrete Manager to obtain certain configs for security reasons).

I'm attempting to get node-config to utilize an async function that returns a promise. I modified my config to a .js file and am utilizing the "asyncConfig" method available on node-config with no luck Link to Node-Config Raw:

Any idea? Or possibly any better ways to do this?

Config File and error below:

const asyncConfig = require('config/async').asyncConfig;
const axios = require('axios');

const seriousSecret = async () => {
  return await axios({
    method: 'get',
    url: 'https://api.chucknorris.io/jokes/random'
  }).then((res)=>{
    return res.data.value;
  });
};

module.exports = {
  host: "localhost",
  port: 3030,
  public: "../public/",
  testing: asyncConfig(seriousSecret),
  paginate: {
    default: 10,
    max: 50
  },
  authentication: {
    entity: "user",
    service: "users",
    secret: "9pKAfA/aJR0eMtp9P3nURwkuopg=",
    authStrategies: [
      "jwt",
      "local"
    ],
    jwtOptions: {
      header: {
        typ: "access"
      },
      audience: "https://yourdomain.com",
      issuer: "feathers",
      algorithm: "HS256",
      expiresIn: "1d"
    },
    local: {
      usernameField: "email",
      passwordField: "password"
    }
  },
  nedb: "../data"
};

error:

output:

{ async: Symbol(asyncSymbol), prepare: [Function (anonymous)], release: [Function (anonymous)] }

daffl commented 3 years ago

Using const testing = await app.get('testing') in your code should still give you the resolved value.