Search…
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. Most web application frameworks have CORS support (as one example of changes that might be required). Another change you might need to make is to support frontends pointing to different instantiations of a backend. Release provides several environment variables to use in your application to assist properly configuring 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, includes https://
  • SERVICE_INGRESS_HOST where SERVICE is the name of your service, no protocol added
  • RELEASE_RANDOMNESS the random unique portion of the URL
1
"""
2
Django settings for backend project.
3
"""
4
import os
5
import re
6
import logging, logging.config
7
8
IS_RELEASE_ENV = bool(os.environ.get('RELEASE_ENV', None))
9
API_INGRESS_HOST = os.environ.get('API_INGRESS_HOST', '')
10
API_INGRESS_URL = os.environ.get('API_INGRESS_URL', '')
11
12
13
if DEBUG:
14
ALLOWED_HOSTS = ['*']
15
elif IS_RELEASE_ENV:
16
logger.info('RELEASE ENV: allowing ingress host: %s' % (API_INGRESS_HOST))
17
ALLOWED_HOSTS = [API_INGRESS_HOST]
18
else:
19
ALLOWED_HOSTS = ['example.com']
20
21
if IS_RELEASE_ENV:
22
BASE_RETURN_URL = API_INGRESS_URL
23
else:
24
BASE_RETURN_URL = 'https://example.com'
Copied!
Here is an example of configuring CORS in python Django

Applications with a frontend and backend

If your app uses react (or other javascript frameworks) 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 react frontend to talk to the backend.
In this example the react frontend service is named frontend and the rails backend service is named backend. Release will generate FRONTEND_INGRESS_URL, FRONTEND_INGRESS_HOST,BACKEND_INGRESS_URL and BACKEND_INGRESS_HOST environment variables for use in your application.
1
module MySweetApp
2
class Application < Rails::Application
3
4
frontend_ingress_host = ENV.fetch('FRONTEND_INGRESS_HOST') { "localhost:4000" }
5
6
# CORS
7
config.middleware.insert_before 0, Rack::Cors do
8
allow do
9
origins frontend_ingress_host
10
11
resource "*",
12
headers: :any,
13
methods: [:get, :post, :put, :patch, :delete, :options, :head],
14
credentials: true
15
end
16
end
17
end
18
end
Copied!
Now need need to configure the frontend service to talk to the backend. In this example we configure axios to talk to our backend.
1
import axios from "axios";
2
import config from "../config";
3
4
const client = axios.create({
5
baseURL: process.env.BACKEND_INGRESS_URL || "http://localhost:3000",
6
withCredentials: true,
7
headers: {
8
"Content-Type": "application/json"
9
}
10
});
Copied!
Last modified 7mo ago