Handle CORS requests for only defined agent routes#457
Handle CORS requests for only defined agent routes#457pilcrowonpaper wants to merge 4 commits intocloudflare:mainfrom
Conversation
🦋 Changeset detectedLatest commit: 7cc567e The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
commit: |
| corsHeaders = {}; | ||
| } | ||
|
|
||
| const response = await routePartykitRequest(request, env as any, { |
There was a problem hiding this comment.
I can replace these any if needed but it's something that needs to be fixed in partyserver imo
There was a problem hiding this comment.
There was a problem hiding this comment.
let's put it back the way it was for now
There was a problem hiding this comment.
As in use Record over any?
| corsHeaders = {}; | ||
| } | ||
|
|
||
| const response = await routePartykitRequest(request, env as any, { |
There was a problem hiding this comment.
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") { |
There was a problem hiding this comment.
don't we want to do this check before calling onBeforeRequest?
There was a problem hiding this comment.
As a user I would assume options.onBeforeRequest() of routeAgentRequest() will be called before anything else.
Currently
routeAgentRequest()resolves anyOPTIONSrequest it receives, regardless of the request path. This PR updatesrouteAgentRequest()to handle preflight requests only for defined agent routes (/agents/NAMESPACE/NAMEand its subroutes).I also improved the JSDoc a bit.