Module App Config
📦 Module for providing application with config as an service
Dependencies
Optional
- http is not required if
IHttpClient
is provided - service-discovery is not required if
IHttpClient
is configure with key appConfig
in http module
Basic
This module should be implemented by the framework and provided by the application framework.
Lifecycle
Configure
case 1: No reference modules are provided (Framework)
The IAppConfigConfigurator
will not have any default IHttpClient
case 2: HttpModule
and ServiceDiscoveryModule
are provided (App)
Before the configurator is created, the module will check ref modules if http has configured a client,
then if not, try to resolve client from service discovery. The client will be assigned to the IAppConfigConfigurator
Initialize
case 1: No IHttpClient
is provided (Framework)
- The module will await init of
HttpModule
- The module will try to create a
IHttpClient
- If no client was created in step 2, it will await init of
ServiceDiscoveryModule
for client - The module will create an
IAppConfigProvider
which is provided to IAppConfigProvider
;
case 2: IHttpClient
is provided (App)
The module will create an IAppConfigProvider
which is provided to IAppConfigProvider
;
Advance Config
🤙🏻 when working within the Fusion eco system none of these configs should be necessary.
Configure your own http client
import { appConfigModuleKey } from '@equinor/fusion-framework-module-app-config'
modules.http.configureClient(
appConfigModuleKey,
{
baseUri: 'https://foo.bar',
defaultScopes: ['foobar/.default'],
},
(client) => {
client.requestHandler.setHeader('x-api-version', '1.0.0-beta.2');
client.requestHandler.add('logger', console.log);
client.responseHandler.add('logger', console.log);
}
);
Configure endpoint generation
config.appConfig.generateUrl = (appKey: string, tag?: string) => {
return `/api/apps/${appKey}/config${tag ? `?tag=${tag}` : ''}`;
}
Configure response selector
config.appConfig.selector = async(result: Response): Promise<AppConfig<TEnvironment>> => {
const data = await result.json();
return normalizeAppConfigResponseData(data);
}
Defining your custom http client
☢️ Boss mode only, really understand framework before even attempt
class MyCustomClient implements IHttpClient {}
config.appConfig.httpClient = new MyCustomClient