Is there any way to find out in which environment (development / development) does the Ember.js application work?

Does Ember.js have an environment concept like Rails (development / testing / production)? For example, I might want to write a bunch of data to the console during development, but not in production. Any way to do this?

To avoid the XY problem, I will explain my actual use case (which is the opposite of the one mentioned): I want to show a specific warning when the application is in production, but will not show it in development. A warning should be displayed if the application does not work through HTTPS. But, since development usually takes place on a local machine with HTTPS disabled, it would be very unpleasant for the developer to constantly show him / her. Therefore, I want to disable the warning during the development process.

+5
source share
2 answers

Ember does not have an environment concept, but you can delegate this responsibility to your server environment (express, rails, whatever you use), you can set the JS variable, cookie value, localStorage, whatever you wish.

Edit: Also, since you are probably testing the local environment, you can check the domain in a URL like localhost, 0.0.0.0, etc.,

for this you can use window.location.host

+3
source

Just pass the property to the page

 var isProduction = false; // dynamically populate App = Ember.Application.create({ LOG_TRANSITIONS: !isProduction, LOG_TRANSITIONS_INTERNAL: !isProduction, log: function(){ if(isProduction) return; console.log.apply(console, arguments); } }); 

And use App.log everywhere.

0
source

Source: https://habr.com/ru/post/1204578/


All Articles