Skip to content

Support CORS #2

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

Merged
merged 5 commits into from
Jan 21, 2025
Merged

Support CORS #2

merged 5 commits into from
Jan 21, 2025

Conversation

daido1976
Copy link
Owner

@daido1976 daido1976 commented Jan 21, 2025

Overview

Issue: #1

Inspired by LocalStack, I considered supporting environment variables like CORS_ALLOWED_ORIGINS, CORS_ALLOWED_HEADERS, and CORS_ALLOWED_METHODS. However, since this is a tool for local development, I wasn’t sure if such detailed configurations were necessary. For now, I decided to support only the ENABLE_CORS environment variable.

The implementation is minimal, setting Access-Control-Allow-Origin: *. This does not allow credentials like cookies to be sent across origins. However, the current implementation does not support cookies at all, so this should not be an issue.

If additional issues are raised, I will consider supporting more detailed configurations.

Note

Operation Check

Check the operation with ENABLE_CORS: true in the test directory.

@daido1976 daido1976 self-assigned this Jan 21, 2025
var rootHandler http.Handler

if enableCors == "true" {
rootHandler = cors.AllowAll().Handler(http.HandlerFunc(lambdaUrlProxyHandler))
Copy link
Owner Author

@daido1976 daido1976 Jan 21, 2025

Choose a reason for hiding this comment

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

At first I tried to use cors.Default(), but it does not allow PUT/DELETE method, etc.

Comment on lines +10 to +11
# Uncomment out when testing for CORS.
# ENABLE_CORS: "true"
Copy link
Owner Author

Choose a reason for hiding this comment

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

I have not written any tests, only operation checks, so I would like to write tests once the specifications are finalized.

@daido1976 daido1976 merged commit 136f4b9 into main Jan 21, 2025
1 check passed
@daido1976 daido1976 deleted the support-cors branch January 21, 2025 03:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant