Add HTML content to a cloudfare page
Hello! I started using Cloudfare yesterday and i really need help...
I followed this tutorial : https://developers.cloudflare.com/workers-ai/get-started/workers-wrangler/
So i used the AI, and it work very well. But i'ld like to add some html content to make the page better. Can someone help me? Here is how my vs code project looks like :
Cloudflare Docs
Deploy a Workers AI project · Cloudflare Workers AI docs
Deploy your first Workers AI project using Cloudflare Workers.
1 Reply
You have a few options.
The easiest without any packages would be to check the
request.url
and serve html based on path, for example like this: https://developers.cloudflare.com/workers/examples/return-html/
and you can get the current path by using the request
const newUrl = new URL(request.url);
if (newUrl.pathname === "/")
.... return html
else if (newUrl.pathname === "/api/"
... ai code
You could also use Cloudflare Pages and Pages Functions (Which support AI Binding, and free unlimited requests for static assets)Cloudflare Docs
Return small HTML page · Cloudflare Workers docs
Documentation for Cloudflare Workers, a serverless execution environment that allows you to create entirely new applications or augment existing ones …