Deploying Remix app on Cloudflare Workers
One of the core features about Remix is to allow deploying your app anywhere. The Remix team maintains several adapters for platforms such as Vercel, Architect, Netlify and also Cloudflare Workers.
The official adapter for Cloudflare Workers is not ready yet at the time this article is written. We will be showing you how to do it with minimal patches using remix-worker-template here.
If you are new to Cloudflare Workers, be sure to signup first. No custom domain nor credit card is required. A default
workers.dev domain will be set with a free plan available.
The environment should be set with node 14+. You should also set up the remix license following the instructions on the dashboard.
Set it up
To begin, create a new repository using the remix-worker-template and clone it to your computer. Install all the packages required by running:
The next step is to setup the wrangler cli. Wrangler is an official tool from Cloudflare for managing your workers. It should be installed together in the previous step. Authenticate the cli using:
npx wrangler login
This will open the Cloudflare account login page. Click
Authorize Wrangler and it is set.
The workers environment is somehow tricky and is hard to verify locally. It is strongly suggest to test it first using the preview service before deploying:
npx wrangler preview
This will deploy your Remix app to a production-alike environment on Cloudflare. Be aware that usages on this environment counts towards your worker quota.
Take it live!
If everything works fine on the preview environment, then you are good to go. Simply run
npx wrangler publish
And now your worker is released on production and should be accessible on the assigned
worker.dev domain as stated on the cli result.