Skip to main content
📞 1-888-784-3881🚀 Start Project
☁️Guides

Cloudflare Workers

Deploy serverless functions at the edge.

⏱️ 18 min read

Overview

Deploy PropTechUSA integrations to Cloudflare Workers for ultra-low latency edge computing.

Setup

1. Install Wrangler

npm install -g wrangler

wrangler login

2. Create Worker

// src/index.ts

export default {

async fetch(request: Request, env: Env): Promise<Response> {

const url = new URL(request.url);

if (url.pathname === '/api/leads' && request.method === 'POST') {

return handleLeadCapture(request, env);

}

return new Response('Not found', { status: 404 });

},

};

async function handleLeadCapture(request: Request, env: Env) {

const data = await request.json();

// Store in D1

await env.DB.prepare(

'INSERT INTO leads (name, email, phone, created_at) VALUES (?, ?, ?, ?)'

).bind(data.name, data.email, data.phone, Date.now()).run();

// Notify via PropTechUSA

await fetch('https://api.proptechusa.ai/v1/leads', {

method: 'POST',

headers: {

'Authorization': Bearer ${env.PROPTECH_API_KEY},

'Content-Type': 'application/json',

},

body: JSON.stringify(data),

});

return Response.json({ success: true });

}

3. Configure wrangler.toml

name = "proptech-worker"

main = "src/index.ts"

compatibility_date = "2024-01-01"

[[d1_databases]]

binding = "DB"

database_name = "proptech"

database_id = "xxxx-xxxx-xxxx"

[vars]

PROPTECH_API_KEY = "pk_live_xxx"

4. Deploy

wrangler deploy