Appearance
App Config
The NestKit AppConfig is a customizable and extensible configuration module designed for managing the main application settings.
Environment variables used in the AppConfig
- PORT: The application port. (optional,
3000by default) - APP_HOST: The application host URL.
- APP_UI_HOST: The application UI host URL.
- APP_ENV: The application environment, which can be
local,development,stage, orproduction. - APP_SERVICE_ACCOUNT_ID: The application service account ID (optional).
- FALLBACK_LANGUAGE: The application's fallback language. (optional,
enby default)
Here's a YAML formatted example of the environment variables used in the AppConfig:
yaml
PORT: 3020
APP_HOST: 'https://app-api.example.com'
APP_UI_HOST: 'https://app.example.com'
APP_ENV: 'local'
APP_SERVICE_ACCOUNT_ID: 'hcu:xxxxxxxxxxx'
FALLBACK_LANGUAGE: 'en'You can adjust the example values according to your application's needs.
How to create and customize AppConfig
Some static parameters can be customized using an options object passed as the first argument to createAppConfig. Below is the list of available options:
name(string): The full name of the application. This is a human-readable name that can be used for display purposes. Example:'Jetstream'.shortname(string): The short name of the application. This is an abbreviated version of the application name, often used for internal purposes or as a prefix for unique identifiers. Example:'js'.
Here's an example of how to use the createAppConfig function with these options:
ts
import { createAppConfig } from '@deep/nest-kit/dist/configs';
export const AppConfig = createAppConfig({
name: 'Jetstream Stock',
shortname: 'stk',
});In this example, the full name of the application is set to 'Jetstream Stock', and the short name is set to 'stk'.
How to inject the AppConfig into a service or a controller
To inject the AppConfig into a service or a controller, you can use the @Inject() decorator provided by NestJS. Here's an example of how to do this in a service:
- Import
ConfigTypeandInjectfrom the respective packages.
ts
import { ConfigType } from '@nestjs/config';
import { Inject } from '@nestjs/common';- Import the
AppConfigfrom your configuration file.
ts
import { AppConfig } from './config';- Use the
@Inject()decorator to inject theAppConfiginto your service or controller class.
ts
@Injectable()
export class YourService {
constructor(
@Inject(AppConfig.KEY) private appConfig: ConfigType<typeof AppConfig>,
) {}
// Your service methods...
}By injecting the AppConfig this way, you have access to the configuration values within your service or controller. You can use the this.appConfig object to read and utilize the configuration values as needed.