RedwoodSDK
In this guide, you will create a new RedwoodSDK ↗ application and deploy it to Cloudflare Workers.
RedwoodSDK is a framework for building server-side web applications on Cloudflare. It is a Vite plugin that provides SSR, React Server Components, Server Functions, and realtime capabilities.
-
Create a new project.
Run the following command, replacing
my-project-namewith your desired project name:npx create-rwsdk my-project-nameyarn dlx create-rwsdk my-project-namepnpx create-rwsdk my-project-name -
Change the directory.
Terminal window cd my-project-name -
Install dependencies.
npm installyarn installpnpm installbun install -
Develop locally.
Run the following command in the project directory to start a local development server. RedwoodSDK is a Vite plugin, so you can use the same development workflow as any other Vite project:
npm run devyarn run devpnpm run devAccess the development server in your browser at
http://localhost:5173, where you should see "Hello, World!" displayed on the page. -
Add your first route.
The entry point of your application is
src/worker.tsx. Open that file in your editor.You will see the
defineAppfunction, which handles requests by returning responses to the client:import { defineApp } from "rwsdk/worker";import { route, render } from "rwsdk/router";import { Document } from "@/app/Document";import { Home } from "@/app/pages/Home";export default defineApp([render(Document, [route("/", () => new Response("Hello, World!"))]),]);Add a
/pingroute handler:import { defineApp } from "rwsdk/worker";import { route, render } from "rwsdk/router";export default defineApp([render(Document, [route("/", () => new Response("Hello, World!")),route("/ping", function () {return <h1>Pong!</h1>;}),]),]);Navigate to
http://localhost:5173/pingto see "Pong!" displayed on the page.Routes can return JSX directly. RedwoodSDK has support for React Server Components, which renders JSX on the server and sends HTML to the client.
-
Deploy your project.
You can deploy your project to a
*.workers.devsubdomain or a Custom Domain, either from your local machine or from any CI/CD system, including Cloudflare Workers CI/CD.Use the following command to build and deploy. If you are using CI, make sure to update your deploy command configuration accordingly.
npm run releaseyarn run releasepnpm run releaseThe first time you run the command it might fail and ask you to create a workers.dev subdomain. Go to the dashboard and open the Workers menu. Opening the Workers landing page for the first time will create a workers.dev subdomain automatically.