-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support api gateway and path based CORS #305
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see the cors middleware in here?
export interface CommandsProps<Service = any> extends ServiceConstructProps { | ||
activityService: ActivityService<Service>; | ||
overrides?: CommandProps<Service>; | ||
eventService: EventService; | ||
workflowService: WorkflowService; | ||
cors?: CorsOptions; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we allow this to be configured per command also?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe later, but API Gateway http doesn't support that. The "custom" approach which doesn't use the infra config would support per operation.
path: command.path, | ||
// itty router supports paths in the form /*, but api gateway expects them in the form /{proxy+} | ||
path: | ||
command.path === "*" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this fragile? What about /abc/*
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thats fine, would become /abc/{proxy+}
if (request.method === "OPTIONS") { | ||
return new HttpResponse(undefined, { | ||
status: 204, | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why 204? A comment would help
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
// CORS expects a 204 or 200, using 204 to match API Gateway
// and accurately reflect NO CONTENT
Advanced and tested CORS support!
Option 1 - Infra Config
Uses API Gateway's CORS configuration and the command worker to handler CORS. APIg adds the CORS headers to any response that matches the configuration (headers, methods, etc) and the $default path returns a 204 response on OPTIONS.
No middleware required, no response headers required, same behavior for ALL paths.
Option 2 - Custom
Uses a command and the router to handler CORS. Requires the commands to return CORS headers manually or via a middleware. Requires the OPTIONS path(s) to be implemented. Allows for customization and dynamic behavior beyond the API level which API gateway allows for.