Define function/callbacks in ENV?


#1

hello :slight_smile:

Could somebody help me to understand why I can not define a function/callback in config/environment.js ENV object?

I see functions/callbacks are removed when we build the application but I can not find where in the ember-cli source code.

Why I want functions/callbacks in ENV ? I use “ember-cli-sentry” addon and we can define some raven-js options in ENV.sentry.ravenOptions. I need one Raven option which is a callback shouldSendCallback (cf https://docs.sentry.io/clients/javascript/config/)

Thanks :smiley:


#2

config/environment.js gets evaluated in node at build time and then JSON.stringified into your app. So it can only hold serializable things.

Perhaps you can open an issue against ember-cli-sentry asking about alternative ways to get config into it, so that it doesn’t need to pass through JSON.stringify.


#3

Thank you :slightly_smiling_face:


#4

there is a similar thing done for trackjs wrapper

// app/instance-initializers/configure-trackjs.js

export function initialize(application) {
  const trackJs = application.container.lookup('service:trackjs');

  trackJs.configure({
    onError(payload, err) {
      // exclude errors from log in page
      if (payload.url && payload.url.indexOf('login') > 0) {
        return false;
      }

      return true;
    }
  });
}

export default {
  name: 'trackjs-error-and-serializer-configuration',
  initialize: initialize
}

Maybe you could do the same here