Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to tell which environment (development/prodution) an Ember.js app is running in?

Does Ember.js have a concept of environment, like for example Rails has (development/testing/production)? For example, I may want to log bunch of data into the console in development, but not in production. Any way to do this?

To avoid the XY problem, I'll explain my actual use case (which is the opposite of the one mentioned): I want to show a certain warning when the app is in production, but not show it in development. The warning should be shown if the app is not running over HTTPS. But, because development usually happens on local machine with HTTPS disabled, it would be quite annoying for the developer to have it shown to him/her all the time. So I want disable the warning in development.

like image 489
adam Avatar asked Sep 29 '22 15:09

adam


1 Answers

There's no concept of environment on Ember, but you can delegate that responsibility to your server environment(express,rails, whatever your are using) you can set a JS variable, a cookie, localStorage value, whatever you want.

Edit: Also, as you are probably testing on a local environment, you could check for the domain in the URL e.g localhost, 0.0.0.0, etc,

for this you can use window.location.host

like image 79
Marcelo Biffara Avatar answered Oct 03 '22 09:10

Marcelo Biffara