Home
Support Forums

Netlify cypress plugin - how to detect the build plugin env?

I am having a hard time configuring the plugin in a way that works with Netlify functions. I have one form which I am submitting using Axios.

The Problem:

const getAxiosBaseUrl = (env) => {
    return env.NODE_ENV === 'netlify' ? env.URL : env.DEPLOY_PRIME_URL
}

Because the env name is always ‘netlify’, the Axios request fails (CORS).

Is there a way how to distinguish where is the app running?

Hi @joska,

You could probably use this plugin: netlify-plugin-inline-functions-env - npm and access the context using process.env.CONTEXT and differentiate branch-deploy and production accordingly.

1 Like

In the end, I realized that this is not a Netlify but Cypress problem. The Netlify build script deployed the web, but the Cypress was then running tests on the feature branch. Since I was unable to force baseUrl config for Cypress, I used the following workaround:

/* In app setings */
const getWebsiteBaseUrl = () => {
  return process.env.NODE_ENV === 'netlify' ? process.env.URL : process.env.DEPLOY_PRIME_URL
}
/* In _redirects file */
# Forces cypress to run postBuild tests against custom domain, to prevent CORS error
https://master--appname.netlify.app/* https://customdomain.tld/:splat 301! 
1 Like

Hey there, @joska :wave:

Thanks for coming back to let us know. We appreciate it! Knowledge sharing will help future Forums members who encounter something similar :netliconfetti: