Skip to main content

Middleware rewrites to other origins

Sean DubbFounder, Easel.sh

Middleware can now rewrite a request to another origin, as on Vercel:

middleware.ts
import { NextResponse, type NextRequest } from "next/server";

export function middleware(request: NextRequest) {
  return NextResponse.rewrite(new URL(request.nextUrl.pathname, "https://api.example.com"));
}

Easel’s edge proxies the request to that origin with the request headers your middleware set. Before, only the path and query were kept and the page was served from your own app.

The middleware function ends as soon as it returns. The edge does the proxying, so no function stays open for the length of the request.

WebSockets through middleware

A WebSocket upgrade through a rewrite to another origin is proxied too, and quiet connections stay open for up to an hour. That covers cases like a dev server’s hot reload socket behind your app’s domain.

Host matchers

has and missing conditions in a middleware matcher now match as patterns, as Next.js does. A matcher like { type: "host", value: "p\\d+-.*" } runs your middleware for those hosts, where before it never matched.

Start deploying

Free to start. Import a repository and get a production URL in a few minutes.