Documentation menu
Documentation

Routing and middleware

The folder tree is the route tree; middleware follows the same hierarchy.

Routes from files

agents/reports/agent.ts maps to /reports/:name. Nested folders create nested prefixes. A folder may contain both an agent and descendants.

Ayjnt routes HTTP and WebSocket upgrades to the named Durable Object instance and serves a co-located app shell on the same route.

Middleware

Place middleware.ts in an agent folder to wrap that route and every descendant. Use it for authentication, tenancy, request context, and policy before an agent wakes.

example
import type { Middleware } from "ayjnt";

const auth: Middleware = async (context, next) => {
  const token = context.request.headers.get("authorization");
  if (!token) return new Response("Unauthorized", { status: 401 });
  return next();
};

export default auth;