Self-hosting Hydrogen
If you don’t want to deploy to Oxygen, then you can host Hydrogen on other JavaScript runtimes, such as Vercel, Netlify, Fly.io, and Cloudflare Workers.
Requirements
Anchor link to section titled "Requirements"- Install the Headless channel. This enables access to the Storefront API and Customer Account API, and lets you manage API tokens.
Steps to update your Hydrogen app
Anchor link to section titled "Steps to update your Hydrogen app"Step 1: Update your Remix adapter
Anchor link to section titled "Step 1: Update your Remix adapter"Remix, Hydrogen’s underlying framework, provides a range of adapters that allow you to adjust your app configuration and build step to target different deployment runtimes.
- In your Hydrogen app, uninstall the Remix adapter for Oxygen:
- Install the Remix adapter for your selected hosting platform. For example:
Step 2: Edit app files for your adapter
Anchor link to section titled "Step 2: Edit app files for your adapter"Typically, when changing Remix adapters, you’ll need to make updates to the following files:
server.js
remix.config.js
app/entry.server.jsx
Remix provides templated examples for a range of adapters. Consult your chosen adapter's template files for specific configurations or required edits.
When making changes, make sure that you continue to pass Hydrogen’s Storefront API client to the Remix loader context. Typically, this involves editing the updated server.js
file using the createRequestHandler
function provided by your chosen adapter.
The following example shows some changes that your app might require:
The cache
object should implement the standard Web Cache API. Check with your chosen hosting platform for more details about its caching implementation.
The waitUntil
method is used in serverless contexts to keep the request function alive after a response has been sent. Check whether your hosting platform supports this pattern, or one like it. For example, Vercel Edge Functions provide a compatible waitUntil
method. This method isn't required when deployed to a stateful Node.js server, because the server keeps running after the response has been returned.
Consult the createStorefrontClient
API reference for the complete list of required and optional parameters.