fix: Nginx proxy configuration for CMS API routes

- Add location blocks for API endpoints to redirect to CMS (port 3001)
- Keep frontend pages on Next.js (port 3000)
- Handle /auth/login specially: GET->frontend, POST->CMS API
- Add maps for detecting API routes

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
2026-03-27 14:04:11 -03:00
parent ff0850b87e
commit 422a143685
2 changed files with 220 additions and 7 deletions
+28 -7
View File
@@ -4,11 +4,32 @@ map $http_x_forwarded_proto $origin_proto {
"" $scheme;
}
# Location for CMS API routes - redirect to CMS service (port 3001)
location ~ ^/(auth|courses|modules|lessons|assets|organization|branding|users|admin|question-bank|test-templates|knowledge-base|api|webhooks|grading|libraries|rubrics|learning-sequences|audit-logs|analytics|webhooks|cohorts|announcements|submissions|peer-reviews|instructors|token-usage|sam|embeddings) {
proxy_pass http://openccb-cms:3001;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# Map to detect API routes that should go to CMS (port 3001)
map $request_uri $cms_api {
default 0;
~^/auth/(register|me|profile|password|reset|verify|logout) 1;
~^/auth/login$ 2; # Special case - handled with if
~^/branding/?$ 1;
~^/courses/?$ 1;
~^/admin/?$ 1;
~^/organization/?$ 1;
~^/users/ 1;
~^/question-bank/ 1;
~^/test-templates/ 1;
~^/knowledge-base/ 1;
~^/api/ 1;
~^/assets/ 1;
~^/modules/ 1;
~^/lessons/ 1;
~^/grading/ 1;
~^/token-usage/ 1;
~^/sam/ 1;
~^/embeddings/ 1;
=/health 1;
}
# For /auth/login, only POST should go to CMS
map "$request_uri:$request_method" $login_post {
default 0;
"~^/auth/login$:POST" 1;
}