Deploy and Test Full-Stack React Apps on Cloudflare

Rate this content
Bookmark
Github

This 3 hour workshop will provide an introduction to the Cloudflare Developer Platform for application developers. It will focus on developing a full-stack React application backed by tests that can guarantee the correctness of its interactions with the resources and APIs provided by the Developer Platform.

The workshop assumes basic knowledge of TypeScript and React — not much beyond what’s needed to build a hello world app in React using TypeScript! Knowledge of the Developer Platform is also not required as everything Cloudflare related will be introduced as part of the workshop.

So if you’re interested in application development on the (fast and inexpensive!) Cloudflare platform then this workshop is for you. By the end of it you will know how to build a fully-fledged, fully-tested, full-stack web application (using React or any framework of your choice) with a comprehensive testing structure that gives you full confidence and peace of mind.


Agenda

The workshop will include live coding, Q&A, and interactive coding sections. The starting code, alongside instructions will be also made available for participants to revisit and dig deeper after

the workshop.

As part of the initial setup we’ll see how to use the C3 tool to easily deploy applications to Cloudflare in a matter of minutes.

Afterwards, we will see how to write code that interacts with the Developer Platform specific resources and APIs, specifically, we’ll use KVs, R2 buckets and Workers AI. We’ll also make sure to test all the code to make sure that it correctly interacts with the aforementioned APIs via the official Workers Vitest integration.

We will then integrate the Workers code with our React app to build a complete full-stack application ready to be deployed to the Cloudflare edge network. We will use playwright to implement an end-to-end (e2e) suite of tests to make sure that the application integrates perfectly with the Cloudflare platform.


Takeaways

- How to develop on the Cloudflare Workers runtime and interact with various Cloudflare resources

- How to develop, comprehensively test and deploy a full-stack application on the Cloudflare Platform

This workshop has been presented at React Summit US 2024, check out the latest edition of this React Conference.

FAQ

The workshop is about deploying and testing full-stack React applications on Cloudflare, focusing on creating a trading card generator app using Remix, Cloudflare Workers, and Pages.

The workshop is led by Christian Sparks from the builds and automation team at Cloudflare and Dario Pietrovic from the frameworks team at Cloudflare.

Participants need a favorite IDE (preferably VS Code), NPM or another package manager, Git, a Cloudflare account (which is free to set up), and some enthusiasm.

Cloudflare Workers is a low-latency serverless runtime that can run in any location worldwide, optimizing responsiveness for users by running near them or their databases.

Remix is used as the full-stack React framework, providing a modern UXDX and integrating seamlessly with Cloudflare services.

Participants are encouraged to ask questions or message the instructors in the chat during the workshop for assistance.

The workshop uses Cloudflare Workers, Cloudflare Pages, and the Remix full-stack React framework.

Testing is performed using Playwright, a popular end-to-end testing framework, ensuring the application behaves as expected in a browser environment.

Workers AI is used for generating images in the trading card generator app, utilizing Cloudflare's AI capabilities.

The card generator app is built using Remix for the full-stack React framework, with backend logic integrating Cloudflare Workers, KV storage, and R2 for storing images.

Dario Piotrowicz
Dario Piotrowicz
Christian Sparks
Christian Sparks
105 min
13 Nov, 2024

Comments

Sign in or register to post your comment.
Video Summary and Transcription
Welcome to the workshop on deploying and testing full stack React apps on Cloudflare. The agenda includes an introduction to the project, UI implementations, deploying the project to the Cloudflare platform, implementing backend logic, and testing the whole application. Cloudflare Pages and Remix are the tech used. The workshop focuses on building a trading card generator app. The first exercise involves implementing the form and backend integration logic. The second step is to create a loader. Backend logic, cloud integration, and statefulness with Cloudflare bindings are covered. Exercise three focuses on implementing the card manager class functionality, including AI functionality. Testing KV and R2 functionality and integrating backend logic with the UI are also covered. Exercise four involves E2E testing with Playwright. Exercise five covers making the code more testable. The workshop concludes with additional ideas and resources.

1. Workshop Introduction

Short description:

Welcome to the workshop on deploying and testing full stack React apps on Cloudflare. Christian Sparks and Dario Pietrovic will be leading the workshop. The agenda includes an introduction to the project, UI implementations, deploying the project to the Cloudflare platform, implementing backend logic, and testing the whole application. Requirements include a preferred IDE, NPM or a preferred package manager, Git, and a Cloudflare account. The workshop will focus on building a trading card generator app using Remix, Cloudflare workers, and pages. Cloudflare workers is a low-latency serverless runtime that can run in any location and offers API differences from Node.js. Join the workshop to learn more.

Hi, everyone. Welcome to the workshop, which is deploying and testing full stack React apps on Cloudflare. Before we get started with the content here, I'm going to give a quick intro to myself and I'll let Dario intro himself. But my name is Christian Sparks. I'm on the builds and automation team at Cloudflare. So if you have ever used Cloudflare pages or you've used Cloudflare workers builds, basically, I work on that type of stuff. So basically, all of the Git integration, if you're building a static site on Cloudflare, I work on that sort of stuff.

And then Dario Pietrovic. I work in the frameworks team at Cloudflare, where we basically try to improve our Cloudflare integration with the various JavaScript frameworks in the ecosystem. And yeah, the workshop, it's about creating a full stack React application and deploy it to our platform. All done alongside comprehensive testing. This is the agenda. It's roughly divided in three one hour slots. We'll start by a quick introduction to the project, then some light UI implementations, and then we'll deploy our project to the Cloudflare platform. Then we'll have a short break. Afterwards, we'll implement some backend logic that actually integrates our application with some resources from the Cloudflare platform. Then another short break. And we'll finally conclude by combining the server-side logic we just implemented in the previous step with our UI, and we test the whole application. And this will bring us to the end of the workshop.

As requirements, they are pretty minimal. But yeah, just your favorite IDE. We usually suggest VS Code, but any IDE should do. NPM or your preferred package manager. Git, as you saw, we have this GitHub repo and the workshop is around this repository. So Git is definitely needed. The Cloudflare account, since we need to integrate with Cloudflare resources and deploy to Cloudflare. So a Cloudflare account is needed. If you haven't set one up, it takes just a few minutes and it's completely free. You don't have to pay anything or anything like that. So it should be pretty good. And finally some enthusiasm, which never hurts.

And yeah. Yeah, sure. So to give a quick overview of what we'll be doing during this workshop, we'll be building a trading card generator app built using Remix, which is a React full-stack framework, Cloudflare workers, and pages. Yes, I'll drop in the repo link. But Cloudflare workers and some other Cloudflare resources. And here's a little demo of our completed applications. You have a little form here, so let's do example. Then we can click Generate, once we've inserted a title and description. It'll take a few seconds, because it is generating an image. And we'll hopefully see a result in a second. And you can see that we've generated a little trading card, a nice-looking trading card. And this is kind of what you'll come away from the workshop with.

Now, to give an overview of what tech we're building this with, the first is Cloudflare workers. So I'm going to give a bit of an overview, because it's a little bit different from a lot of the JavaScript platforms you might have used before. Typically, people will do stuff in Node or in the browser, but workers is a little bit different. The key is that it's a low-latency serverless runtime, and it's sort of regionless. The idea is that it can run in pretty much any location in the world, and you can choose its placement and make it run near a user, far away from a user, near certain databases that you might have in order to optimize the responsiveness for any user of your application. It's also V8-based, so kind of the same tech as Chrome and Node.js, but there's some API differences. Pretty performant.

2. Tech and Exercise Introduction

Short description:

Cloudflare Pages is the tech we'll be using for hosting static assets and backend workers. Remix is the full-stack React framework we'll be using. It has good support for Cloudflare and can be easily migrated to React v7. The workshop repo contains a set of GitHubs for easy navigation. The first exercise involves implementing the form and backend integration logic for the UI. Feel free to ask questions throughout the workshop.

And the way that we sandbox it, this is kind of more detailed than you need, but we use V8 isolates in order to minimize cold starts. So what that means is, if nobody has accessed your application in a while on other serverless platforms, you might experience a pretty slow request, so like cold starts of almost half a second or a second, versus with Cloudflare, we try to minimize it to be zero, so there's basically no difference between a cold start and a hot start. It's also pretty cheap. Free plan, $5 a month, there's a lot of requests included. The workshop today can be completed entirely within the free plan with many, many requests there, so you don't need to worry about that. And specifically, the tech that we'll be using is Cloudflare Pages, which provides a combo of static assets hosting, as well as some backend workers capability, which is kind of ideal for our use case today, which is a full-stack web app. I'll hand it off to Dario to talk about React.

Cool, so yeah, the full-stack React framework we'll be using is Remix. Probably everyone here should be pretty familiar with that. But anyway, just to give a light introduction, it's a full-stack React framework with a nice UXDX and all the bells and whistles you'd expect from a modern framework. One thing to mention is that the Remix team is kind of migrating it to become part of React Routers v7. But yeah, anything we'll be using today, it should be pretty trivially migratable anyway to React v7 when it comes, so it's not like what we'll present today, it's going to be obsolete soon. Anyway, what we'll also implement can be implemented with any full-stack React framework or even any full-stack JavaScript framework in general, so it is a bit Remix-based, but the concepts are pretty generic.

As a full-stack React framework on Cloudflare, there are a few other alternatives, for example the big one is NxJS. There are also newer and experimental ones like Quark and 10-steps. But yeah, anyway, we chose to go with Remix because it has very good out-of-the-box support for Cloudflare. It has a polished API for accessing Cloudflare resources, as we'll see in the workshop. We also have a nice starter template in our C3 tool for creating a new Remix project and I can actually very quickly show you what I mean with that. If you're not familiar with our Create tool, it's a simple CLI tool which you can run via C3 and create Cloudflare or your package manager alternative. You can choose where to create your application. There are various options, and as I mentioned, we have an option for Remix. So basically, if you were to use the C3 tool, here we would scaffold and create a Remix application ready for you to just deploy on Cloudflare. Anyways, I was just showing you the tool, but we're not going to use it as in our repo. We already scaffolded the whole application for you. Speaking of which, this is the repo. Christian already shared it. If you can please clone it. Anyways, to give a very high level introduction of the repo, there is simply a welcome section with a link to the slides. I mean, I think you have it, but it's there if you need it. And one important thing to mention, we have a set of GitHubs so that if you want, you can jump to any point of the workshop at any time. So yeah, if you, for example, get lost at any point, or you want to skip an exercise or check the solution for an exercise or anything you want, you can simply check out the various tags, which are listed here. Yes. Anyway, we also live code the various exercises, solutions, and anything like that. So hopefully you should not need to jump too much through tags, but if you need to, they're there for you. We can start with the first exercise. Here we are also listing the various GitHubs related to this exercise. Anyways, for each exercise in our workshop, we have a readme file, which you can find under exercises. And yes, this first exercise, it's regarding implementing the form of our UI. So right now we have a simple partially implemented UI, and the task of this first exercise is to implement the form with the action and loader logic, so the backend integration logic for that. So yeah, we'll give you a few minutes to get acquainted with the repo and start the project and start working on the first step, then in a few minutes we can live code the first step together and we'll also continue with this structure for the other steps. So yeah, if you want to get started with the exercise. And by the way, at any point if you have any questions or anything, just shout or message us in chat or whatever you want. So let's actually start looking at the solution for the first step together. And let me actually... I already forked... How do I get rid of this? Okay, I already cloned the repo. So let's actually do a simple npm install. And we can start the application with npm run dev. So we do get our... So this is the starting application.

Watch more workshops on topic

Designing Effective Tests With React Testing Library
React Summit 2023React Summit 2023
151 min
Designing Effective Tests With React Testing Library
Top Content
Featured Workshop
Josh Justice
Josh Justice
React Testing Library is a great framework for React component tests because there are a lot of questions it answers for you, so you don’t need to worry about those questions. But that doesn’t mean testing is easy. There are still a lot of questions you have to figure out for yourself: How many component tests should you write vs end-to-end tests or lower-level unit tests? How can you test a certain line of code that is tricky to test? And what in the world are you supposed to do about that persistent act() warning?
In this three-hour workshop we’ll introduce React Testing Library along with a mental model for how to think about designing your component tests. This mental model will help you see how to test each bit of logic, whether or not to mock dependencies, and will help improve the design of your components. You’ll walk away with the tools, techniques, and principles you need to implement low-cost, high-value component tests.
Table of contents- The different kinds of React application tests, and where component tests fit in- A mental model for thinking about the inputs and outputs of the components you test- Options for selecting DOM elements to verify and interact with them- The value of mocks and why they shouldn’t be avoided- The challenges with asynchrony in RTL tests and how to handle them
Prerequisites- Familiarity with building applications with React- Basic experience writing automated tests with Jest or another unit testing framework- You do not need any experience with React Testing Library- Machine setup: Node LTS, Yarn
How to Start With Cypress
TestJS Summit 2022TestJS Summit 2022
146 min
How to Start With Cypress
Featured WorkshopFree
Filip Hric
Filip Hric
The web has evolved. Finally, testing has also. Cypress is a modern testing tool that answers the testing needs of modern web applications. It has been gaining a lot of traction in the last couple of years, gaining worldwide popularity. If you have been waiting to learn Cypress, wait no more! Filip Hric will guide you through the first steps on how to start using Cypress and set up a project on your own. The good news is, learning Cypress is incredibly easy. You'll write your first test in no time, and then you'll discover how to write a full end-to-end test for a modern web application. You'll learn the core concepts like retry-ability. Discover how to work and interact with your application and learn how to combine API and UI tests. Throughout this whole workshop, we will write code and do practical exercises. You will leave with a hands-on experience that you can translate to your own project.
Detox 101: How to write stable end-to-end tests for your React Native application
React Summit 2022React Summit 2022
117 min
Detox 101: How to write stable end-to-end tests for your React Native application
Top Content
WorkshopFree
Yevheniia Hlovatska
Yevheniia Hlovatska
Compared to unit testing, end-to-end testing aims to interact with your application just like a real user. And as we all know it can be pretty challenging. Especially when we talk about Mobile applications.
Tests rely on many conditions and are considered to be slow and flaky. On the other hand - end-to-end tests can give the greatest confidence that your app is working. And if done right - can become an amazing tool for boosting developer velocity.
Detox is a gray-box end-to-end testing framework for mobile apps. Developed by Wix to solve the problem of slowness and flakiness and used by React Native itself as its E2E testing tool.
Join me on this workshop to learn how to make your mobile end-to-end tests with Detox rock.
Prerequisites- iOS/Android: MacOS Catalina or newer- Android only: Linux- Install before the workshop
API Testing with Postman Workshop
TestJS Summit 2023TestJS Summit 2023
48 min
API Testing with Postman Workshop
Top Content
WorkshopFree
Pooja Mistry
Pooja Mistry
In the ever-evolving landscape of software development, ensuring the reliability and functionality of APIs has become paramount. "API Testing with Postman" is a comprehensive workshop designed to equip participants with the knowledge and skills needed to excel in API testing using Postman, a powerful tool widely adopted by professionals in the field. This workshop delves into the fundamentals of API testing, progresses to advanced testing techniques, and explores automation, performance testing, and multi-protocol support, providing attendees with a holistic understanding of API testing with Postman.
1. Welcome to Postman- Explaining the Postman User Interface (UI)2. Workspace and Collections Collaboration- Understanding Workspaces and their role in collaboration- Exploring the concept of Collections for organizing and executing API requests3. Introduction to API Testing- Covering the basics of API testing and its significance4. Variable Management- Managing environment, global, and collection variables- Utilizing scripting snippets for dynamic data5. Building Testing Workflows- Creating effective testing workflows for comprehensive testing- Utilizing the Collection Runner for test execution- Introduction to Postbot for automated testing6. Advanced Testing- Contract Testing for ensuring API contracts- Using Mock Servers for effective testing- Maximizing productivity with Collection/Workspace templates- Integration Testing and Regression Testing strategies7. Automation with Postman- Leveraging the Postman CLI for automation- Scheduled Runs for regular testing- Integrating Postman into CI/CD pipelines8. Performance Testing- Demonstrating performance testing capabilities (showing the desktop client)- Synchronizing tests with VS Code for streamlined development9. Exploring Advanced Features - Working with Multiple Protocols: GraphQL, gRPC, and more
Join us for this workshop to unlock the full potential of Postman for API testing, streamline your testing processes, and enhance the quality and reliability of your software. Whether you're a beginner or an experienced tester, this workshop will equip you with the skills needed to excel in API testing with Postman.
Monitoring 101 for React Developers
React Summit US 2023React Summit US 2023
107 min
Monitoring 101 for React Developers
Top Content
WorkshopFree
Lazar Nikolov
Sarah Guthals
2 authors
If finding errors in your frontend project is like searching for a needle in a code haystack, then Sentry error monitoring can be your metal detector. Learn the basics of error monitoring with Sentry. Whether you are running a React, Angular, Vue, or just “vanilla” JavaScript, see how Sentry can help you find the who, what, when and where behind errors in your frontend project. 
Workshop level: Intermediate
Testing Web Applications Using Cypress
TestJS Summit - January, 2021TestJS Summit - January, 2021
173 min
Testing Web Applications Using Cypress
Top Content
WorkshopFree
Gleb Bahmutov
Gleb Bahmutov
This workshop will teach you the basics of writing useful end-to-end tests using Cypress Test Runner.
We will cover writing tests, covering every application feature, structuring tests, intercepting network requests, and setting up the backend data.
Anyone who knows JavaScript programming language and has NPM installed would be able to follow along.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

Network Requests with Cypress
TestJS Summit 2021TestJS Summit 2021
33 min
Network Requests with Cypress
Top Content
Cecilia Martinez, a technical account manager at Cypress, discusses network requests in Cypress and demonstrates commands like cydot request and SCI.INTERCEPT. She also explains dynamic matching and aliasing, network stubbing, and the pros and cons of using real server responses versus stubbing. The talk covers logging request responses, testing front-end and backend API, handling list length and DOM traversal, lazy loading, and provides resources for beginners to learn Cypress.
Testing Pyramid Makes Little Sense, What We Can Use Instead
TestJS Summit 2021TestJS Summit 2021
38 min
Testing Pyramid Makes Little Sense, What We Can Use Instead
Top Content
Featured Video
Gleb Bahmutov
Roman Sandler
2 authors
The testing pyramid - the canonical shape of tests that defined what types of tests we need to write to make sure the app works - is ... obsolete. In this presentation, Roman Sandler and Gleb Bahmutov argue what the testing shape works better for today's web applications.
Full-Circle Testing With Cypress
TestJS Summit 2022TestJS Summit 2022
27 min
Full-Circle Testing With Cypress
Top Content
Cypress is a powerful tool for end-to-end testing and API testing. It provides instant feedback on test errors and allows tests to be run inside the browser. Cypress enables testing at both the application and network layers, making it easier to reach different edge cases. With features like AppActions and component testing, Cypress allows for comprehensive testing of individual components and the entire application. Join the workshops to learn more about full circle testing with Cypress.
Test Effective Development
TestJS Summit 2021TestJS Summit 2021
31 min
Test Effective Development
Top Content
This Talk introduces Test Effective Development, a new approach to testing that aims to make companies more cost-effective. The speaker shares their personal journey of improving code quality and reducing bugs through smarter testing strategies. They discuss the importance of finding a balance between testing confidence and efficiency and introduce the concepts of isolated and integrated testing. The speaker also suggests different testing strategies based on the size of the application and emphasizes the need to choose cost-effective testing approaches based on the specific project requirements.
Playwright Test Runner
TestJS Summit 2021TestJS Summit 2021
25 min
Playwright Test Runner
Top Content
The Playwright Test Runner is a cross-browser web testing framework that allows you to write tests using just a few lines of code. It supports features like parallel test execution, device emulation, and different reporters for customized output. Code-Gen is a new feature that generates code to interact with web pages. Playwright Tracing provides a powerful tool for debugging and analyzing test actions, with the ability to explore trace files using TraceViewer. Overall, Playwright Test offers installation, test authoring, debugging, and post-mortem debugging capabilities.
Everyone Can Easily Write Tests
TestJS Summit 2023TestJS Summit 2023
21 min
Everyone Can Easily Write Tests
Playwright is a reliable end-to-end testing tool for modern web apps that provides one API, full isolation, fast execution, and supports multiple languages. It offers features like auto-weighting, retrying assertions, seamless testing of iframes and shadow DOM, test isolation, parallelism, and scalability. Playwright provides tools like VS Code extension, UiMode, and Trace Viewer for writing, debugging, and running tests. Effective tests prioritize user-facing attributes, use playwright locators and assertions, and avoid testing third-party dependencies. Playwright simplifies testing by generating tests, providing code generation and UI mode, and allows for easy running and debugging of tests. It helps in fixing failed tests and analyzing DOM changes, fixing locator mismatches, and scaling tests. Playwright is open source, free, and continuously growing.