4

In my Angular4 application i ejected the webpack config and used dotenv module to read from a .env file and use those config variables in the application. Since i updated to Angular6 the "ng eject" is depricated and i am using angular-cli. I am looking for a workaroud for this problem (either using a config file or system environment variables).

If i can make a reference in Spring Framework in the application.properties file

spring.datasource.username = ${MYSQL_DB_USERNAME}

MYSQL_DB_USERNAME is environment variable. I would like to use this behavior in environment.ts

Ivan Kirchev
  • 133
  • 1
  • 9
  • environment.ts **is** a config file. And you're not telling which concrete problem you're trying to solve. – JB Nizet Jul 06 '18 at 12:52
  • Yes but i want to use sensitive information without pushing it to the repo – Ivan Kirchev Jul 06 '18 at 12:55
  • If those sensitive info is in the generated JavaScript files, distributed to each and every user of the application, putting it in the repo won't really make it less secure. – JB Nizet Jul 06 '18 at 12:57
  • This is just for development. This sensitive information will be served to the user after login. But since the login hasn't been implemented yet using .env file with configuration that is not uploaded to the repo is working fine. – Ivan Kirchev Jul 06 '18 at 13:26

1 Answers1

1

I dont think you are able to do that unless maybe you are using SSR? Webpack for angular 6 at the moment is disabled, they said they would re-add with some customization but majority will be done in angular.json. so for now no ng eject.

I think the best approach might be to make a restApi call to your backend on bootstrap to load and retrieve any variables you may require.

Ng Eject: https://github.com/angular/angular-cli/issues/10618

Taranjit Kang
  • 2,510
  • 3
  • 20
  • 40