Edge Functions for Website (Vercel Edge)

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
    1214
  • 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
    823
  • image_bitrix-bitrix-24-1c_fixper_448_0.png
    Website development for FIXPER company
    815

Edge Functions Development for Websites (Vercel Edge)

Vercel Edge Functions run on the Vercel Edge Network — on 100+ nodes worldwide, milliseconds from the user. Cold start less than 1 ms. This distinguishes them from regular Vercel Functions, which run in a single AWS region.

When Edge, When Regular Functions

Edge Functions are optimal for: personalization (A/B testing, geolocation), redirects and rewrites based on conditions, middleware authentication, header and response transformation, cache validation by cookie.

Regular Node.js Functions are needed when: Node.js API is required (fs, crypto, native modules), TCP connection to PostgreSQL, execution time > 30 s, memory > 128 MB.

Edge Runtime uses Web API (like in browsers), not Node.js API.

Middleware for A/B Testing

File middleware.ts in the root of Next.js project:

import { NextRequest, NextResponse } from "next/server";

export function middleware(request: NextRequest) {
  const url = request.nextUrl.clone();

  // A/B test for homepage
  if (url.pathname === "/") {
    const bucket = request.cookies.get("ab-bucket")?.value;

    if (!bucket) {
      const newBucket = Math.random() < 0.5 ? "a" : "b";
      const response = NextResponse.rewrite(
        new URL(newBucket === "b" ? "/home-variant" : "/", request.url)
      );
      response.cookies.set("ab-bucket", newBucket, { maxAge: 86400 * 30 });
      return response;
    }

    if (bucket === "b") {
      url.pathname = "/home-variant";
      return NextResponse.rewrite(url);
    }
  }

  return NextResponse.next();
}

export const config = {
  matcher: ["/", "/pricing", "/features"],
};

Geolocation and Personalization

import { NextRequest, NextResponse } from "next/server";
import { geolocation } from "@vercel/functions";

export function middleware(request: NextRequest) {
  const { country, city } = geolocation(request);

  // Redirect to localized version
  if (country === "RU" && !request.nextUrl.pathname.startsWith("/ru")) {
    return NextResponse.redirect(
      new URL(`/ru${request.nextUrl.pathname}`, request.url)
    );
  }

  // Add geo data to headers for components
  const response = NextResponse.next();
  response.headers.set("x-user-country", country || "unknown");
  response.headers.set("x-user-city", city || "unknown");
  return response;
}

Edge API Route

// app/api/edge-data/route.ts
import { NextRequest, NextResponse } from "next/server";

export const runtime = "edge";

export async function GET(request: NextRequest) {
  const { searchParams } = new URL(request.url);
  const id = searchParams.get("id");

  // Fetch works natively in Edge Runtime
  const data = await fetch(`https://api.external.com/data/${id}`, {
    headers: { Authorization: `Bearer ${process.env.API_KEY}` },
    // next.js cache: cache for 60 seconds
    next: { revalidate: 60 },
  }).then(r => r.json());

  return NextResponse.json(data, {
    headers: { "Cache-Control": "s-maxage=60, stale-while-revalidate=120" }
  });
}

Route Protection via JWT

import { NextRequest, NextResponse } from "next/server";
import { jwtVerify } from "jose";

const JWT_SECRET = new TextEncoder().encode(process.env.JWT_SECRET);

export async function middleware(request: NextRequest) {
  if (request.nextUrl.pathname.startsWith("/dashboard")) {
    const token = request.cookies.get("auth-token")?.value;

    if (!token) {
      return NextResponse.redirect(new URL("/login", request.url));
    }

    try {
      await jwtVerify(token, JWT_SECRET);
      return NextResponse.next();
    } catch {
      const response = NextResponse.redirect(new URL("/login", request.url));
      response.cookies.delete("auth-token");
      return response;
    }
  }
}

jose is the only JWT library compatible with Edge Runtime (uses Web Crypto API instead of node:crypto).

Edge Runtime Limitations

  • No node:fs, node:path, node:crypto (Web Crypto available)
  • No native npm packages
  • Memory: 128 MB
  • CPU time: 30 ms (Hobby), unlimited on Pro
  • No direct connections to PostgreSQL (Neon and PlanetScale support HTTP API)

Timeframe

Middleware with geolocation and A/B testing — 1–2 days. Edge API Routes with caching and JWT protection — 2–3 days.