Skip to content

Conversation

pilcrowonpaper
Copy link
Contributor

Currently routeAgentRequest() resolves any OPTIONS request it receives, regardless of the request path. This PR updates routeAgentRequest() to handle preflight requests only for defined agent routes (/agents/NAMESPACE/NAME and its subroutes).

I also improved the JSDoc a bit.

Copy link

changeset-bot bot commented Sep 12, 2025

🦋 Changeset detected

Latest commit: 7cc567e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
agents Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

pkg-pr-new bot commented Sep 12, 2025

Open in StackBlitz

npm i https://pkg.pr.new/cloudflare/agents@457

commit: 7cc567e

@whoiskatrin whoiskatrin added on the roadmap Feature accepted and planned for implementation enhancement New feature or request labels Sep 15, 2025
corsHeaders = {};
}

const response = await routePartykitRequest(request, env as any, {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can replace these any if needed but it's something that needs to be fixed in partyserver imo

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

let's put it back the way it was for now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As in use Record over any?

corsHeaders = {};
}

const response = await routePartykitRequest(request, env as any, {
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's put it back the way it was for now

console.warn(
"Received an OPTIONS request, but cors was not enabled. Pass `cors: true` or `cors: { ...custom cors headers }` to routeAgentRequest to enable CORS."
);
if (resolvedRequest.method === "OPTIONS") {
Copy link
Collaborator

Choose a reason for hiding this comment

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

don't we want to do this check before calling onBeforeRequest?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As a user I would assume options.onBeforeRequest() of routeAgentRequest() will be called before anything else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request on the roadmap Feature accepted and planned for implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants