Skip to content

Commit 63fbc3b

Browse files
fix: cors
1 parent 422f06a commit 63fbc3b

2 files changed

Lines changed: 24 additions & 16 deletions

File tree

.idea/workspace.xml

Lines changed: 12 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nginx/templates/default.conf.template

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ server {
6363
proxy_hide_header 'Access-Control-Allow-Credentials';
6464

6565
# Set CORS origin for WebSocket
66-
set $cors_origin "";
67-
if ($http_origin ~* "^https?://(localhost:[0-9]+|127\.0\.0\.1:[0-9]+|.*\.vercel\.app|ielts-mate-fe\.vercel\.app|tootsstore\.online)$") {
66+
set $cors_origin "*";
67+
68+
# For requests with Origin header, use the actual origin for credential support
69+
if ($http_origin != "") {
6870
set $cors_origin $http_origin;
6971
}
7072

@@ -104,8 +106,10 @@ server {
104106

105107
# Add CORS headers for SSE with specific origin handling
106108
# Set the allowed origin based on the request origin
107-
set $cors_origin "";
108-
if ($http_origin ~* "^https?://(localhost:[0-9]+|127\.0\.0\.1:[0-9]+|.*\.vercel\.app|ielts-mate-fe\.vercel\.app|tootsstore\.online)$") {
109+
set $cors_origin "*";
110+
111+
# For requests with Origin header, use the actual origin for credential support
112+
if ($http_origin != "") {
109113
set $cors_origin $http_origin;
110114
}
111115

@@ -150,14 +154,11 @@ server {
150154
proxy_pass http://api-gateway:9191;
151155

152156
# Add CORS headers for regular API requests
153-
set $cors_origin "";
154-
if ($http_origin ~* "^https?://(localhost:[0-9]+|127\.0\.0\.1:[0-9]+|.*\.vercel\.app|ielts-mate-fe\.vercel\.app|tootsstore\.online)$") {
155-
set $cors_origin $http_origin;
156-
}
157+
set $cors_origin "*";
157158

158-
# Allow same-origin requests (no origin header)
159-
if ($http_origin = "") {
160-
set $cors_origin "*";
159+
# For requests with Origin header, use the actual origin for credential support
160+
if ($http_origin != "") {
161+
set $cors_origin $http_origin;
161162
}
162163

163164
add_header 'Access-Control-Allow-Origin' $cors_origin always;

0 commit comments

Comments
 (0)