Edge computing with Cloudflare Workers. Runs in 300+ cities worldwide with D1 database and KV storage.
export default {
async fetch(request, env) {
const url = new URL(request.url);
if (url.pathname === '/api/data') {
const rows = await env.DB.prepare(
'SELECT * FROM items LIMIT 10'
).all();
return Response.json(rows.results);
}
return new Response('Hello from the edge!');
},
};Open in RoadCode