-
Notifications
You must be signed in to change notification settings - Fork 64
Little bit refactoring cors to separate module, add auth0 config example #83
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
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
102fba6
fix tool descriptions from config
bvt123 48bee71
Merge pull request #1 from bvt123/codex/fix-missing-custom-tool-descr…
bvt123 4ce5d8e
Merge branch 'centralmind:main' into main
bvt123 d52c815
refactor CORS handle SSE to allow mcp-protocol-version header
Slach b73ea37
feat: enhance OAuth plugin configuration handling and metadata genera…
Slach af5a66e
fix: handle full URLs in OAuth plugin configuration
Slach dbadcf8
add aider to gitignore
Slach fb87fe4
Merge branch 'main' of github.com:bvt122/gateway into add_cors_to_sse
Slach d268055
debug auth0 oauth
Slach 1446099
update auth0 docs
Slach c314d48
Merge branch 'centralmind:main' into add_cors_to_sse
Slach 4b5a185
Merge branch 'main' of github.com:centralmind/gateway into add_cors_t…
Slach 0e57001
Merge branch 'add_cors_to_sse' of github.com:Slach/gateway into add_c…
Slach d3e1694
rollback unexpected changes in README.md
Slach 0089f76
Merge pull request #1 from Altinity/add_cors_to_sse
Slach File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -365,3 +365,4 @@ $RECYCLE.BIN/ | |
|
|
||
| # Local configs | ||
| *.secret.yaml | ||
| .aider* | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package cors | ||
|
|
||
| import "net/http" | ||
|
|
||
| // ApplyCORSHeaders adds the standard CORS headers to a response | ||
| // For handlers that are not wrapped in middleware | ||
| func ApplyCORSHeaders(w http.ResponseWriter, allowedMethods string) { | ||
| w.Header().Set("Access-Control-Allow-Origin", "*") | ||
| w.Header().Set("Access-Control-Allow-Methods", allowedMethods+", OPTIONS") | ||
| w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization, mcp-protocol-version") | ||
| } | ||
|
|
||
| // HandlePreflight checks if the request is a preflight OPTIONS request and handles it | ||
| // Returns true if the request was handled (caller should return immediately) | ||
| func HandlePreflight(w http.ResponseWriter, r *http.Request) bool { | ||
| if r.Method == http.MethodOptions { | ||
| w.WriteHeader(http.StatusOK) | ||
| return true | ||
| } | ||
| return false | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,42 +1,18 @@ | ||
| package oauth | ||
|
|
||
| import ( | ||
| "github.com/centralmind/gateway/cors" | ||
| "net/http" | ||
| ) | ||
|
|
||
| // CORSMiddleware applies standard CORS headers to the response | ||
| func CORSMiddleware(handler http.Handler) http.Handler { | ||
| return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| // Add CORS headers | ||
| w.Header().Set("Access-Control-Allow-Origin", "*") | ||
| w.Header().Set("Access-Control-Allow-Methods", "GET, POST, OPTIONS") | ||
| w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization") | ||
|
|
||
| // Handle preflight OPTIONS request | ||
| if r.Method == "OPTIONS" { | ||
| w.WriteHeader(http.StatusOK) | ||
| cors.ApplyCORSHeaders(w, "GET, POST") | ||
| if cors.HandlePreflight(w, r) { | ||
| return | ||
| } | ||
|
|
||
| // Call the original handler | ||
| handler.ServeHTTP(w, r) | ||
| }) | ||
| } | ||
|
|
||
| // ApplyCORSHeaders adds the standard CORS headers to a response | ||
| // For handlers that are not wrapped in middleware | ||
| func ApplyCORSHeaders(w http.ResponseWriter, allowedMethods string) { | ||
| w.Header().Set("Access-Control-Allow-Origin", "*") | ||
| w.Header().Set("Access-Control-Allow-Methods", allowedMethods+", OPTIONS") | ||
| w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization") | ||
| } | ||
|
|
||
| // HandlePreflight checks if the request is a preflight OPTIONS request and handles it | ||
| // Returns true if the request was handled (caller should return immediately) | ||
| func HandlePreflight(w http.ResponseWriter, r *http.Request) bool { | ||
| if r.Method == "OPTIONS" { | ||
| w.WriteHeader(http.StatusOK) | ||
| return true | ||
| } | ||
| return false | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
cors.ApplyCORSHeaders -> cors.ApplyHeaders