Deploy RedwoodJS Web Side with Cloudflare Pages

Cloudflare Pages is a Jamstack platform for frontend developers to collaborate and deploy websites. It’s a lot like {{ insert_favorite_Jamstack_host }}. Simply connect to a GitHub repo, supply the necessary build commands and publish directories, and deploy your site to the world with just git push.

At this time it is not yet possible to deploy the Redwood api with Cloudflare Workers. However, we can simply delete the api directory and deploy just the web side.

Create a Redwood App

The code for this article can be found on my GitHub.

yarn create redwood-app redwood-cloudflare-pages
cd redwood-cloudflare-pages

Delete api directory

rm -rf api

Generate home page

yarn rw g page home /

Include the following in HomePage.js.

const HomePage = () => {
  return (
    <>
      <h1>Redwood+Cloudflare Pages 🚀</h1>
      <p>Woot!</p>
    </>
  )
}

export default HomePage

Start development server

yarn rw dev

Create GitHub Repo

Create a blank repository on GitHub with the same name as your Redwood project.

Initialize repository

Initialize a git repo in your newly created Redwood project.

git init
git add .
git commit -m "Nailed it"
git branch -M main

Add remote to project

Make sure to use your own repo when setting the remote.

git remote add origin https://github.com/ajcwebdev/redwood-cloudflare-pages.git

Push to main

git push -u origin main

Connect GitHub repo to Cloudflare Pages

Sign up for Cloudflare Pages.

Click “Create a project.”

Select your Redwood project and click the “Begin setup” button at the bottom.

Your project name and production branch will be set automatically.

The build settings are blank. Enter:

  • yarn rw build web for the build command
  • web/dist for the build output directory

Click “Save and deploy.”

Go take a nice long walk around the block, grab some coffee, take out your dry cleaning, file your taxes, complete that 10,000 piece puzzle you’ve been putting off, and then come back and your website build should be done.

Once the build finishes you will see the build and deployment settings at the bottom and a link to your site at the top.

Click the link to redwood-cloudflare-pages.pages.dev and you should see the following page.

3 Likes

Thanks for sharing!

I’ve updated the repo, anyone who wants to see the test build & deploy to CloudFlare Pages can find it here: GitHub - smartykit/redwood-cloudflare-pages: Demo RedwoodJS package to deploy to Cloudflare Pages. Use `yarn rw build web` as build command and `web/dist` as output directory

Live version of the deploy: https://redwood-cloudflare-pages-43w.pages.dev/

1 Like

I found the problem when I deploy and with my log :

2023-09-11T10:27:06.671719Z	Cloning repository...
2023-09-11T10:27:07.829017Z	From https://github.com/bdloner/iboardgameth
2023-09-11T10:27:07.829741Z	 * branch            b0272fb6122a621adbaef3552cbfe77c7b4dbd69 -> FETCH_HEAD
2023-09-11T10:27:07.829971Z	
2023-09-11T10:27:07.929993Z	HEAD is now at b0272fb upgrade rw 6.2
2023-09-11T10:27:07.930644Z	
2023-09-11T10:27:08.035998Z	
2023-09-11T10:27:08.067314Z	Success: Finished cloning repository files
2023-09-11T10:27:10.144652Z	Detected the following tools from environment: nodejs@lts/*
2023-09-11T10:27:10.145683Z	, npm@9.5.1, yarn@3.6.1
2023-09-11T10:27:10.146436Z	Installing nodejs lts/*
2023-09-11T10:27:10.146608Z	
2023-09-11T10:27:10.231082Z	mkdir: cannot create directory '/opt/buildhome/.asdf/installs/nodejs/lts/*': No such file or directory
2023-09-11T10:27:10.822813Z	Trying to update node-build... ok
2023-09-11T10:27:10.866358Z	node-build: definition not found: 18
2023-09-11T10:27:10.874551Z	Error: Exit with error code: 1
2023-09-11T10:27:10.874858Z	    at ChildProcess.<anonymous> (/snapshot/dist/run-build.js)
2023-09-11T10:27:10.875042Z	    at Object.onceWrapper (node:events:652:26)
2023-09-11T10:27:10.875193Z	    at ChildProcess.emit (node:events:537:28)
2023-09-11T10:27:10.875348Z	    at ChildProcess._handle.onexit (node:internal/child_process:291:12)
2023-09-11T10:27:10.884948Z	Failed: build command exited with code: 1
2023-09-11T10:27:11.835419Z	Failed: error occurred while running build command

how to fixed?

Hello - anyone deploying web to cloudflare pages with redwood >= 7 ?