I have a sensitive API key that my Angular 5 service needs access to. Since I plan on deploying this application to a cloud service that uses environment variables for production configuration (i.e. Heroku), ideally I would like to store this sensitive key as an environment variable rather than exposing it through an environment file that is publicly viewable in the repository. Unfortunately, it seems like Angular 5 does not support this (e.g. Use process.env in Angular 5 environment).
Is there a technique that I can use that will allow me to define my sensitive key as an environment variable and have my Angular service fetch it? Or is there another technique that I can use to allow me to not have to store my sensitive key in my repository, but still allow my production Angular service to access it?
Service Example
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Injectable()
export class SpecialService {
url = 'https://www.specialservice.com/';
constructor(private http: HttpClient) { }
getValue(userParm: string) {
const SUPERSECRETKEY = 'fetch me from an env variable, please';
return this.http.get(this.url + 'query?function=DO_SOMETHING&parm1='
+ userParm + '&apikey=' + SUPERSECRETKEY);
}
}
I know I can use src/environments/environment.prod.ts for storing variables to be used in production versus src/environments/environment.ts for storing development variables. Unfortunately, this requires me to commit my sensitive variables to the production file which would be visible in the repository, which is not desirable. My preference is to use some sort of environment variable that I manually define in the production environment.
Thanks for any suggestions or ideas!