0

I am trying to deploy an app based on angular to bluemix and I want to use system variables (process.env). Somehow this does not work and process only contains title=browser and an empty env object. I set them on the environment but I can't get the dotenv to work. The app is based on the angular-cli.

Does somebody know how to safely store api keys with or without dotenv and such?

EDIT: some code from the app.module. I also tried it in the main.ts file but to no avail.

export function restServiceLoader(logger: NGXLogger, http: HttpClient): any {

  logger.debug('test is ' + process.env.TEST);

  return new ApiDataService(logger, http);

}
5
  • 3
    it should work some code will help on how you are using the same Commented Jan 12, 2018 at 7:54
  • 1
    Was the app created using angular-cli? Commented Jan 12, 2018 at 7:56
  • I'm sure you don't want to do it, at least when it comes to public projects. Giving up the env variables to the public is surly not a good idea. Commented Jan 12, 2018 at 7:58
  • Maybe this helps you with API Keys. You can use the environment file of Angular. stackoverflow.com/questions/46441288/… Commented Jan 12, 2018 at 8:02
  • The app was created with the angular-cli! Commented Jan 12, 2018 at 8:03

2 Answers 2

0

The environment variable you are setting on Bluemix is for the container hosting your Angular application. The environment variable you are trying to read in your Angular application is for the browser's environment e.g. where the Angular application is running.

You can either use a class to keep your configuration as constants, as suggested by John and explained here or you can make a call to your backend to get configurations that are only kept at the backend.

Design-wise, sensitive configurations should not be kept in your frontend/Angular application e.g. browser environment because it is vulnerable there and you have little to no control on how it is secured and maintained.

Sign up to request clarification or add additional context in comments.

Comments

-1

You can use the environment.ts file located under the src/environments folder which looks something like this:

export const environment = {
  production: false,
  api:'http://someApi.com'
};

Then use the environment in your component/service:

import {environment} from '../environments/environment';

and use it like this: environment.api anywhere in that component or service.

I would not store private keys in the environment file, only public ones.

4 Comments

But what if i want to store private keys?
store the private keys on your server. Or on bluemix. I am not familiar with bluemix though.
So make a seperate environment file on the server?
I would create an environment.api in Angular, sending api request to a proxy server. Store and use the private key on the proxy server. How you do that to work with bluemix is unknown to me. Sorry I cannot be of more help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.