Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions router/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Route precedence:

- `/meet-with-will`, `/meet-with-khaliq`, and `/virtual-office` redirect to their external meeting destinations at the edge.
- `/cloud*` routes to the Agent Relay Cloud Next.js app.
- `/observer/file*` routes to the RelayFile observer app, expected to be built with `basePath: "/observer/file"`.
- `/observer*` routes to the Relaycast observer app.
Expand Down
25 changes: 25 additions & 0 deletions router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ const FILE_OBSERVER_PATH_PREFIX = "/observer/file";
const OBSERVER_PATH_PREFIX = "/observer";
const CLOUD_PATH_PREFIX = "/cloud";
const WEBHOOK_ORIGIN_FLAG_KEY = "WEBHOOK_ORIGIN";
const VANITY_REDIRECTS = new Map<string, string>([
["/meet-with-will", "https://calendar.app.google/RqLuQyT3dYe5e2YdA"],
["/meet-with-khaliq", "https://calendly.com/khaliq-agent-relay/30min"],
["/virtual-office", "https://meet.google.com/ijx-gpfb-brt"],
]);

// Header set by webhook-worker's queue consumer
// (`packages/webhook-worker/src/queue-consumer.ts`'s `buildForwardHeaders`) on
Expand Down Expand Up @@ -77,6 +82,17 @@ function isCloudPath(pathname: string): boolean {
return isPathWithinPrefix(pathname, CLOUD_PATH_PREFIX);
}

export function getVanityRedirect(hostname: string, pathname: string): string | undefined {
if (hostname !== PRIMARY_HOST) {
return undefined;
}

const normalizedPathname = (pathname.length > 1
? pathname.replace(/\/$/, "")
: pathname).toLowerCase();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: .toLowerCase() was added to enable case-insensitive vanity-route matching, but there doesn't appear to be a test exercising mixed-case or uppercase paths (e.g. /Meet-With-Will). Adding a case-variant test case would prevent regressions if the normalization logic changes.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At router/index.ts, line 92:

<comment>`.toLowerCase()` was added to enable case-insensitive vanity-route matching, but there doesn't appear to be a test exercising mixed-case or uppercase paths (e.g. `/Meet-With-Will`). Adding a case-variant test case would prevent regressions if the normalization logic changes.</comment>

<file context>
@@ -87,9 +87,9 @@ export function getVanityRedirect(hostname: string, pathname: string): string |
+  const normalizedPathname = (pathname.length > 1
     ? pathname.replace(/\/$/, "")
-    : pathname;
+    : pathname).toLowerCase();
   return VANITY_REDIRECTS.get(normalizedPathname);
 }
</file context>

return VANITY_REDIRECTS.get(normalizedPathname);
}

// True only for the exact paths the webhook worker knows how to handle. Used
// to gate worker forwarding so unrelated routes under /api/v1/webhooks/* (e.g.
// the Composio OAuth callback) still reach the Lambda.
Expand Down Expand Up @@ -309,6 +325,15 @@ export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
const url = new URL(request.url);

const vanityRedirect = getVanityRedirect(url.hostname, url.pathname);
if (vanityRedirect) {
const redirectUrl = new URL(vanityRedirect);
url.searchParams.forEach((value, key) => {
redirectUrl.searchParams.set(key, value);
});
return Response.redirect(redirectUrl.toString(), 302);
}
Comment thread
willwashburn marked this conversation as resolved.

// Per-key rate limiting runs BEFORE any worker routing so a runaway
// workspace gets bounded everywhere — including webhook ingress and
// /cloud* traffic. The bypass list inside maybeRateLimit exempts
Expand Down
43 changes: 43 additions & 0 deletions router/test/vanity-redirects.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { describe, expect, it, vi } from "vitest";

import worker, { getVanityRedirect } from "../index.js";

const redirects = [
["/meet-with-will", "https://calendar.app.google/RqLuQyT3dYe5e2YdA"],
["/meet-with-khaliq", "https://calendly.com/khaliq-agent-relay/30min"],
["/virtual-office", "https://meet.google.com/ijx-gpfb-brt"],
] as const;

function buildCtx(): ExecutionContext {
return {
waitUntil: () => undefined,
passThroughOnException: () => undefined,
} as unknown as ExecutionContext;
}

describe("router vanity redirects", () => {
it.each(redirects)("redirects %s at the edge", async (path, destination) => {
const cloudWebWorker = { fetch: vi.fn() };
const response = await worker.fetch(
new Request(`https://agentrelay.com${path}?utm_source=test`),
{
CLOUD_APP_ORIGIN: "https://origin.test.invalid",
CLOUD_WEB_WORKER: cloudWebWorker,
},
buildCtx(),
);

expect(response.status).toBe(302);
expect(response.headers.get("location")).toBe(destination);
expect(cloudWebWorker.fetch).not.toHaveBeenCalled();
});
Comment on lines +19 to +33

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Update the test to assert that query parameters (such as utm_source) are preserved during the redirect, matching the updated redirect behavior.

  it.each(redirects)("redirects %s at the edge", async (path, destination) => {
    const cloudWebWorker = { fetch: vi.fn() };
    const response = await worker.fetch(
      new Request("https://agentrelay.com" + path + "?utm_source=test"),
      {
        CLOUD_APP_ORIGIN: "https://origin.test.invalid",
        CLOUD_WEB_WORKER: cloudWebWorker,
      },
      buildCtx(),
    );

    expect(response.status).toBe(302);
    const expectedUrl = new URL(destination);
    expectedUrl.searchParams.set("utm_source", "test");
    expect(response.headers.get("location")).toBe(expectedUrl.toString());
    expect(cloudWebWorker.fetch).not.toHaveBeenCalled();
  });


it.each(redirects)("accepts a trailing slash for %s", (path, destination) => {
expect(getVanityRedirect("agentrelay.com", `${path}/`)).toBe(destination);
});
Comment on lines +35 to +37

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Add test coverage for case-insensitivity to ensure that mixed-case or uppercase vanity URLs are correctly matched and redirected.

Suggested change
it.each(redirects)("accepts a trailing slash for %s", (path, destination) => {
expect(getVanityRedirect("agentrelay.com", `${path}/`)).toBe(destination);
});
it.each(redirects)("accepts a trailing slash and mixed case for %s", (path, destination) => {
expect(getVanityRedirect("agentrelay.com", path + "/")).toBe(destination);
expect(getVanityRedirect("agentrelay.com", path.toUpperCase())).toBe(destination);
});


it("does not redirect another hostname or a nested path", () => {
expect(getVanityRedirect("origin-web.agentrelay.com", "/meet-with-will")).toBeUndefined();
expect(getVanityRedirect("agentrelay.com", "/meet-with-will/details")).toBeUndefined();
});
});
Loading