Appearance
Gcp Config
The Google Cloud Project configuration (GcpConfig
) provides an easy way to set up and manage your Google Cloud Project within your application. It enables you to configure the project ID and associated storage buckets with their respective aliases, making it easier to access and manage these resources."
GcpConfig
can be used with the GcsModule
, providing necessary configuration options to manage and interact with Google Cloud Storage resources.
Environment variables used in the GcpConfig
:
Here is a list of environment variables used in the GcpConfig
:
- GCP_PROJECT: Google Cloud Project ID.
- GCP_BUCKETS: Google Cloud Buckets configuration as a JSON string.
Here's a YAML formatted example of the environment variables used in the GcpConfig
:
yaml
GCP_PROJECT: the-google-project-id
GCP_BUCKETS: |
[
{"name":"nestkit-bucket-01", "alias": "bucket01"},
{"name":"nestkit-bucket-03", "alias": "bucket02", "type": "us"},
{"name":"nestkit-bucket-04", "alias": "bucket02", "type": "eu"},
{"name":"nestkit-bucket-05", "alias": "bucket02", "type": "asia"}
]
You can adjust the example values according to your application's needs.
How to create GcpConfig
Here's an example of how to use the createGcpConfig
to create GcpConfig
:
ts
import { createGcpConfig } from '@deeepvision/nest-kit/dist/configs';
export const GcpConfig = createGcpConfig();
How to inject the GcpConfig into a service or a controller
To inject the GcpConfig
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
ConfigType
andInject
from the respective packages.
ts
import { ConfigType } from '@nestjs/config';
import { Inject } from '@nestjs/common';
- Import the
GcpConfig
from your configuration file.
ts
import { GcpConfig } from './config';
- Use the
@Inject()
decorator to inject theGcpConfig
into your service or controller class.
ts
@Injectable()
export class YourService {
constructor(
@Inject(GcpConfig.KEY) private gcpConfig: ConfigType<typeof GcpConfig>,
) {}
// Your service methods...
}
By injecting the GcpConfig
this way, you have access to the configuration values within your service or controller. You can use the this.gcpConfig
object to read and utilize the configuration values as needed.