hapipal / confidence

Dynamic, declarative configurations
Other
263 stars 43 forks source link

Support objects as values. #30

Closed gergoerdosi closed 9 years ago

gergoerdosi commented 9 years ago

Fixes: https://github.com/hapijs/confidence/issues/29

genadis commented 7 years ago

@patrickkettner, Sorry to revive old issue, I've read the discussion in #30 as well. Having same issue as @gergoerdosi .

I'm familiar with confidence from hapi js projects. But find it useful for other NodeJS applications as well. Even application with no frameworks for running on embedded devices.

In my use case I have different sub modules all configured from main configuration (confidence). Based on env I configure a logger (bunyan). And wanted to pass it to all my sub models with the rest of the parameters (As mentioned not hapi project so no plugin system). Something like that:

Logger = .... // set logger based on some configuration

internals.appConfig = {
    $meta: 'example',
    $filter: 'env',
    $default: {},
    production: {
    },
    $base: {
        app: {
            activeDrivers: 1,
            logger: Logger,
        },
        mqtt: {
            clientOptions: {
                qos: 1,
                retain: false,
                logger: Logger
            },
            logger: Logger
        },
        controllers: [
            {
                $filter: 'env',
                $default: {},
                production: {
                },
                $base: {
                    port: {
                        dev: 'dev/ttyS0',
                    },
                    logger: Logger
                }
            },
            {
                $filter: 'env',
                $default: {},
                production: {
                },
                $base: {
                    port: {
                        dev: '/dev/ttyS1'
                    },
                    logger: Logger
                }
            }
         ]
    }
}

Unfortunately getting RangeError: Maximum call stack size exceeded error. I can think of a number of work arounds, non of them pretty as to having a centralized place for configuration. (Logger is only one example, there can be multiple objects I wanted to pass along)

+1 for support of this feature