sigao-app-config v1.0.1
SigaoAppConfig
This library is used for loading application configuration settings from a local JSON file. By loading from a JSON file, users are able to change applications settings via a build process without rebuilding the application, as is the case with Angular's environment variables.
NOTE: This method of managing application variables does not in any way obfuscate values from the client. Never put sensitive values in your configuration file.
Usage
Install the package
Run npm install sigao-app-config
Import the module
Place the following in your app imports:
// Optional converter function for modifying the JSON value.
// If you're comfortable working with pure JSON, leave this parameter out
const customConverter = (json: any) => {
// Convert the JSON object here
return CONVERTED_VALUE;
};
@NgModule({
declarations: [AppComponent],
imports: [
SigaoAppConfigModule.forRoot('MY_CONFIG.json', customConverter)
],
bootstrap: [AppComponent]
})
export class AppModule { }
Note, the first parameter of the "forRoot" function is a path. For exmaple, if you included your configuration in your assests folder, the correct value would be assets/MY_CONFIG.json
Create the configuration json
Place a file with the extension ".json" in your project. For the sake of convenience, it is recommended that you place the file directly in the "src" folder
Include the file in your application
By default, Angular will not recognize your configuration file as a file to be included. To change this, open your angular.json file and find the "assets" property of your projects (projects > YOUR_PROJECT > architect > build > assets). In that array add the path to your file like so:
"assets": [
"src/favicon.ico",
"src/assets",
"src/MY_CONFIG.json"
],
Use the service
Any component/service that needs configuration settings can now inject the SigaoAppConfigService.
import SigaoAppConfigService from "sigao-app-config";
@Injectable()
export class MyService {
constructor(public configService: SigaoAppConfigService){
console.log(configService.getConfig())
}
}
If the custom converter has been used to convert the JSON to a custom object type, you can send type parameters to the "getConfig()" function in order to access methods and additional properties like so:
const myConfig: MyCustomConfigType = this.configService.getConfig<MyCustomConfigType>();
Additional Info
Special thanks to https://jbt.github.io/markdown-editor/ for helping me learn README markdown.
Sigao Usage Disclaimer
This package (along with other "Sigao" marked packages) is designed to be used within our tech stack to support our development efforts. While significant effort has been made to ensure that these packages are tested and maintained, mistakes happen, and there is a good possibility the bug won't be addressed unless it directly impacts our specific use case.
If you encounter a bug that you'd like addressed, feel free to reach out to us and we'll see what we can do!