> For the complete documentation index, see [llms.txt](https://docs.release.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.release.com/guides-and-examples/advanced-guides/designing-for-multiple-environments.md).

# Designing for multiple environments

When running your application in different environments, like those provided by Release, you may need to make some minor changes to your code to support multi-variations. You may need to adapt your code depending on how your framework handles [CORS](https://en.wikipedia.org/wiki/Cross-origin_resource_sharing), or you may want to support frontends pointing to different instantiations of a backend. Release provides several environment variables to use in your application to assist you to properly configure your application to work in multiple environments.

Release provides the following environment variables:

* `RELEASE_ENV`: set to `true` for all Release environments
* `SERVICE_INGRESS_URL`: where `SERVICE` is the name of your service, including `https://`
* `SERVICE_INGRESS_HOST`: where `SERVICE` is the name of your service, no protocol added
* `RELEASE_RANDOMNESS`: the random unique portion of the URL

For example, the following code configures CORS in Django:

```python
"""
Django settings for backend project.
"""
import os
import re
import logging, logging.config

IS_RELEASE_ENV = bool(os.environ.get('RELEASE_ENV', None))
API_INGRESS_HOST = os.environ.get('API_INGRESS_HOST', '')
API_INGRESS_URL = os.environ.get('API_INGRESS_URL', '')


if DEBUG:
    ALLOWED_HOSTS = ['*']
elif IS_RELEASE_ENV:
    logger.info('RELEASE ENV: allowing ingress host: %s' % (API_INGRESS_HOST))
    ALLOWED_HOSTS = [API_INGRESS_HOST]
else:
    ALLOWED_HOSTS = ['example.com']

if IS_RELEASE_ENV:
    BASE_RETURN_URL = API_INGRESS_URL
else:
    BASE_RETURN_URL = 'https://example.com'
```

## Applications with a frontend and backend

If your app uses a JavaScript framework, such as React, on the frontend, and Rails on the backend, you will need to configure the Rails backend to allow traffic from the frontend. You will also need to configure the frontend to talk to the backend.

In the following example, a Rails backend service named `backend` is configured to allow traffic from a React frontend service named `frontend`:

```ruby
module MySweetApp
  class Application < Rails::Application

    frontend_ingress_host = ENV.fetch('FRONTEND_INGRESS_HOST') { "localhost:4000" }

    # CORS
    config.middleware.insert_before 0, Rack::Cors do
      allow do
        origins frontend_ingress_host

        resource "*",
          headers: :any,
          methods: [:get, :post, :put, :patch, :delete, :options, :head],
          credentials: true
      end
    end
  end
end
```

Release will generate the following environment variables to use in your application:

* `FRONTEND_INGRESS_URL`
* `FRONTEND_INGRESS_HOST`
* `BACKEND_INGRESS_URL`
* `BACKEND_INGRESS_HOST`

Now we need to configure the frontend service to talk to the backend. Here we configure Axios to talk to our backend:

```javascript
import axios from "axios";
import config from "../config";

const client = axios.create({
  baseURL: process.env.BACKEND_INGRESS_URL || "http://localhost:3000",
  withCredentials: true,
  headers: {
    "Content-Type": "application/json"
  }
});
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.release.com/guides-and-examples/advanced-guides/designing-for-multiple-environments.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
