Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FLOW-15] Add middleware for CORS in localhost env #124

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

addison-ch
Copy link
Collaborator

@addison-ch addison-ch commented Mar 21, 2024

  • Added custom middleware to allow CORS from localhost origins
  • Added alias for chi middleware because it was conflicting with our module name 馃ゲ

@addison-ch addison-ch changed the title [FLOW-15] Add middleware to fix CORS errors in localhost env [FLOW-15] Add middleware for CORS in localhost env Mar 21, 2024
middleware.Recoverer,
middleware.RequestID,
middleware.Timeout(10*time.Second),
middleware.CorsMiddleware(), // Enable CORS for development environments
Copy link
Member

Choose a reason for hiding this comment

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

Hmm I think we want to enable this only if we're running the Docker container locally - we don't want this to affect prod such that any requests coming from localhost bypass CORS

Maybe we could read in an env var for local dev and only do a Router.Use for this middleware if a dev flag is set

import "net/http"

// CORS middleware for localhost environments
func CorsMiddleware() func(http.Handler) http.Handler {
Copy link
Member

Choose a reason for hiding this comment

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

maybe just to be explicit?

Suggested change
func CorsMiddleware() func(http.Handler) http.Handler {
func CorsLocalhostMiddleware() func(http.Handler) http.Handler {

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.

None yet

2 participants