Serverless Functions for Website (Cloudflare Workers)

Our company is engaged in the development, support and maintenance of sites of any complexity. From simple one-page sites to large-scale cluster systems built on micro services. Experience of developers is confirmed by certificates from vendors.
Development and maintenance of all types of websites:
Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Our competencies:
Development stages
Latest works
  • image_website-b2b-advance_0.png
    B2B ADVANCE company website development
    1212
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1161
  • image_websites_belfingroup_462_0.webp
    Website development for BELFINGROUP
    852
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1041
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    822
  • image_bitrix-bitrix-24-1c_fixper_448_0.png
    Website development for FIXPER company
    815

Serverless Functions Development for Websites (Cloudflare Workers)

Cloudflare Workers run on V8 isolates — not Node.js and not containers. This provides cold start in less than 1 ms and execution on 300+ edge nodes worldwide. The free tier includes 100,000 requests per day.

Difference from AWS Lambda and Vercel Functions

Workers run on every Cloudflare PoP — a user from Moscow gets an answer from the nearest node, not from us-east-1. This is crucial for latency-sensitive tasks. Limitation: Workers use Web API, not Node.js API — fs, child_process, native modules are unavailable.

Basic Worker

// src/index.ts
export default {
  async fetch(request: Request, env: Env): Promise<Response> {
    const url = new URL(request.url);

    if (url.pathname === "/api/contact" && request.method === "POST") {
      return handleContact(request, env);
    }

    if (url.pathname === "/api/geo") {
      return handleGeo(request);
    }

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

async function handleContact(request: Request, env: Env): Promise<Response> {
  const data = await request.json<{ name: string; email: string; message: string }>();

  // Send via Resend API
  const emailResponse = await fetch("https://api.resend.com/emails", {
    method: "POST",
    headers: {
      Authorization: `Bearer ${env.RESEND_API_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      from: "[email protected]",
      to: ["[email protected]"],
      subject: `Message from ${data.name}`,
      text: `${data.name} (${data.email}): ${data.message}`,
    }),
  });

  if (!emailResponse.ok) {
    return Response.json({ error: "Email send failed" }, { status: 500 });
  }

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

// Geolocation from Cloudflare headers
function handleGeo(request: Request): Response {
  const cf = (request as any).cf;
  return Response.json({
    country: cf?.country,
    city: cf?.city,
    timezone: cf?.timezone,
    latitude: cf?.latitude,
    longitude: cf?.longitude,
  });
}

Wrangler and Deployment

# wrangler.toml
name = "my-site-api"
main = "src/index.ts"
compatibility_date = "2024-11-01"

[vars]
ENVIRONMENT = "production"

[[routes]]
pattern = "yourdomain.com/api/*"
zone_name = "yourdomain.com"
npm install -g wrangler
wrangler login
wrangler dev          # local development
wrangler deploy       # deployment

Secrets:

wrangler secret put RESEND_API_KEY
wrangler secret put DATABASE_URL

Workers KV: Data Storage

KV is a key-value store, eventually consistent. Good for caching, sessions, configuration.

// Binding in wrangler.toml
// [[kv_namespaces]]
// binding = "CACHE"
// id = "abc123..."

export default {
  async fetch(request: Request, env: Env & { CACHE: KVNamespace }) {
    const cacheKey = new URL(request.url).pathname;
    const cached = await env.CACHE.get(cacheKey);

    if (cached) {
      return new Response(cached, {
        headers: { "Content-Type": "application/json", "X-Cache": "HIT" }
      });
    }

    const data = await fetchFreshData(request);
    await env.CACHE.put(cacheKey, JSON.stringify(data), { expirationTtl: 300 });

    return Response.json(data);
  }
};

D1: SQLite on Edge

D1 is Cloudflare's serverless SQLite database. Good for small datasets (up to 10 GB).

export default {
  async fetch(request: Request, env: Env & { DB: D1Database }) {
    const { results } = await env.DB.prepare(
      "SELECT * FROM products WHERE category = ? ORDER BY created_at DESC LIMIT 20"
    ).bind("electronics").all();

    return Response.json(results);
  }
};

Workers Limitations

  • CPU time: 10 ms (free), 30 s (Paid)
  • Memory: 128 MB
  • No Node.js built-ins (fs, path, crypto — only Web Crypto API)
  • No long-lived connections to PostgreSQL (use Hyperdrive or HTTP API)

Hyperdrive: PostgreSQL from Workers

export default {
  async fetch(request: Request, env: Env & { HYPERDRIVE: Hyperdrive }) {
    const client = new Client({ connectionString: env.HYPERDRIVE.connectionString });
    await client.connect();

    const result = await client.query("SELECT * FROM users WHERE id = $1", [userId]);
    await client.end();

    return Response.json(result.rows[0]);
  }
};

Hyperdrive proxies connections to external PostgreSQL through a connection pool on Cloudflare's side, solving the latency problem when connecting to a remote database.

Timeframe

Basic Worker with routing and 3–5 endpoints — 2–3 days. KV and D1 integration, CI/CD via GitHub Actions — plus 2 days.