drake035
drake035

Reputation: 2897

How to check whether a browser app is running on local dev server vs. online staging server?

I want to call a component only on our staging server but not on my local machine:

    <save-drafts-timer v-if="!environment === 'development'" />

    ...

    data () {
      return {
        environment: process.env.NODE_ENV
      }
    }

By doing this, will this component be always (and only) called on staging server? If not, is there some reliable way to do that?

Upvotes: 0

Views: 481

Answers (1)

T. Short
T. Short

Reputation: 3614

I don't know much about your project, but process.env.NODE_ENV is a server side environment variable, and Vue is a client side application, so it will not have access to that.

You would have to pass that environment variable to your client somehow. If you are using webpack, you could use the DefinePlugin feature:

https://webpack.js.org/plugins/define-plugin/

This will allow you to define a global variable which you could then access inside of Vue.

Upvotes: 1

Related Questions