How to host backend on CloudFare Pages?

So currently I have a React Typescript webapp ready to go. I have separated the whole project into separate frontend and backend subdirectories, with their own node_modules folder and package.json and other such things. The frontend is typescript and the backend is Express, with Axios connecting them both. However, when I deployed my webapp to CloudFare Pages, the frontend works but my newsletter subscription form isn't working. Is there any way I can have a backend with my frontend on Pages?
5 Replies
AlphaCentauri
AlphaCentauri•14mo ago
?pages-webserver
Flare
Flare•14mo ago
Cloudflare Pages is for static content (HTML, CSS, JS, images and other such files). It will not run a webserver such as Express, Koa or the likes. If you're using those to serve static content then you can just remove that part and use Pages! If you're doing more dynamic content you can use Functions (https://developers.cloudflare.com/pages/platform/functions). It will run code on request (so still not a webserver in the conventional sense). This would allow for more dynamic content though especially with KV (Key Value storage) and Durable Objects (transactional data storage). Functions are natively integrated with Pages so are super easy to get up and running along your website. Otherwise, a good old VPS or dedicated server from one of the many hosts out there is for you.
MinistryOfHummus
MinistryOfHummusOP•14mo ago
could you elaborate? wait nvm lol thank you I appreciate it
AlphaCentauri
AlphaCentauri•14mo ago
No worries 😀
MinistryOfHummus
MinistryOfHummusOP•14mo ago
one last question is it safe to host environment variables on cloudflare pages directly? will the client be able to see the keys on their frontend even when I use cloudflare pages to store the environment variables?

Did you find this page helpful?