Environments
Hydrogen storefronts can contain multiple environments, to which you make deployments.
Each environment is linked to a branch in your Hydrogen app’s Git repository:
Environment | Associated Git branch |
---|---|
Production | Default branch. You can edit the production environment to select a different branch. |
Custom environments | Optional. Define multiple custom environments, with each one linked to its own branch. |
Preview | All other branches not linked to a production or custom environment. |
Each environment can have its own set of environment variables, which allows you to use different values in your app depending on the environment. This can be useful for testing, feature development, and security.
Managing environments
Anchor link to section titled "Managing environments"The production and preview environments are required for all storefronts, and can't be deleted. In addition to these required environments, you can optionally create additional custom environments to develop new features, test out ideas, and more.
Create a new environment
Anchor link to section titled "Create a new environment"- In your Hydrogen storefront, click Storefront settings.
- Click Environments and variables.
- Click Add environment.
- Select an existing repository branch to link to the environment, or create a new branch.
- Type a name for the branch. The name determines the environment URL.
- Select whether to make the environment public or private.
- Optional: Under Copy environment variables, select an existing environment to copy variables from.
- Click Save.
Update an environment
Anchor link to section titled "Update an environment"- In your Hydrogen storefront, click Storefront settings.
- Click Environments and variables.
- Click the environment to edit.
- Make your changes.
- Click Save.
Delete a custom environment
Anchor link to section titled "Delete a custom environment"- In your Hydrogen storefront, click Storefront settings.
- Click Environments and variables.
- Click the environment to delete.
- Click Delete environment.
Environment variables
Anchor link to section titled "Environment variables"Each environment can have its own set of environment variables, which are key-value pairs. Variable keys can be called in your app code, and return contexual values for the environment where the deployment is running. Each environment can have a maximum of 110 unique environment variables.
Accessing environment variable values in your app
Anchor link to section titled "Accessing environment variable values in your app"Hydrogen automatically adds your environment variables to a request's context
object. You can access the values of environment variables from a loader or action:
Create a new environment variable
Anchor link to section titled "Create a new environment variable"- In your Hydrogen storefront, click Storefront settings.
- Click Environments and variables.
- Under Variables, click Add variable.
- Under Key, type a key. It's a common convention for keys to use all-capital letters and underscores, such as
EXAMPLE_API_TOKEN
. - Under Value, add the value.
- Optional: Check Make this value secret to hide the value after saving. This can be useful for sensitive information like API keys.
- Under Environments, select the environments where the value should be returned.
- Click Save.
Click Add another value to add additional values for other environments.
Edit an environment variable
Anchor link to section titled "Edit an environment variable"You can edit keys and values, as well as which environments they apply to.
- In your Hydrogen storefront, click Storefront settings.
- Click Environments and variables.
- Click the environment variable to update.
- Make your changes.
- Click Save.
You might want to redeploy any environments that require the updated variables.
Delete an environment variable
Anchor link to section titled "Delete an environment variable"Deleting an environment variable deletes the key and all its associated values.
- In your Hydrogen storefront, click Storefront settings.
- Click Environments and variables.
- Click the environment variable to delete.
- Click Delete variable.
- Click Delete variable to confirm.
Required environment variables
Anchor link to section titled "Required environment variables"Oxygen requires the following variables to query your store's data. They're automatically added when you create a storefront. Some variables are read-only, meaning they can’t be edited directly.
Variable | Description | Read-only? |
---|---|---|
PRIVATE_STOREFRONT_API_TOKEN |
Your private Storefront API access token, used for server-side queries. This token is read-only, but can be rotated. | Yes |
PUBLIC_CUSTOMER_ACCOUNT_API_CLIENT_ID |
Your Customer Account API client ID. This token is read-only, but can be rotated. | Yes |
PUBLIC_CUSTOMER_ACCOUNT_API_URL |
The URL endpoint that accepts Customer Account API authentication requests. | Yes |
PUBLIC_STORE_DOMAIN |
Your store domain ID (such as example.myshopify.com ). |
Yes |
PUBLIC_STOREFRONT_API_TOKEN |
Your Storefront API access token, used for client-side queries. | Yes |
PUBLIC_STOREFRONT_ID |
Your Hydrogen storefront’s numeric ID. | Yes |
SESSION_SECRET |
The value that Remix uses to sign session cookies. | No |
Rotate your private Storefront API token
Anchor link to section titled "Rotate your private Storefront API token"If your private Storefront API access token is exposed publicly, then you should rotate it to protect sensitive data and prevent abuse.
- In your Hydrogen storefront, click Storefront settings.
- Click Storefront API
- Under Rotate private access token, click Generate new token
- Click Generate new token to confirm.
- Optional: If you have other client apps using your private API token, then update them with the new token value.
- Under Past private access token, click Delete.
- Push a commit to your GitHub repo to trigger a new deployment. At this time, Oxygen doesn't automatically re-deploy environments when rotating API tokens.
Immutability
Anchor link to section titled "Immutability"Oxygen deployments are immutable, which includes their environment variable values. This means any changes to environment variables don’t affect deployments that were made in the past.
If you create or update environment variables, then you need to redeploy before your changes will take effect.
Environment visibility
Anchor link to section titled "Environment visibility"By default, environments are private, which means that you need to be logged into your store to view them. You can also make an environment public, meaning anyone with the URL can view it.
Toggle an environment to public or private
Anchor link to section titled "Toggle an environment to public or private"- In your Hydrogen storefront, click Storefront settings.
- Click Environments and variables.
- Click the environment to edit.
- Under URL privacy, select either Public or Private.
- Click Save.
Public environment limits
Anchor link to section titled "Public environment limits"Stores have a limited number of public environments available, based on their plan.
Plan | Public environment limit |
---|---|
Pause and build | 0 |
Basic | 1 |
Shopify | 1 |
Advanced | 1 |
Shopify Plus | 25 |
Plus Partner Sandbox stores | 1 |
Environment URLs
Anchor link to section titled "Environment URLs"Each environment has an automatically generated URL. By default, this URL always points to the most recent deployment to that environment.
- Learn how to deploy your Hydrogen storefront to Oxygen and other runtimes.