Cấu hình
Gateway không có bề mặt biến env IGNIS và không có bảng
Configuration. Cấu hình của nó là ba file cộng với hằng số build-time của portal.
1. Config tĩnh Traefik
Nguồn: packages/gateway/config/traefik.yml
| Section | Giá trị | Ghi chú |
|---|---|---|
api.dashboard | true | Dashboard được bật (auth qua router file-provider, không phải api.insecure) |
entryPoints.web | :80 | Entrypoint HTTP — nhận traffic từ edge Nginx |
entryPoints.traefik | :8080 | Dashboard + Prometheus metrics |
| HTTPS entrypoint | vắng | TLS kết thúc tại edge Nginx, không phải Traefik |
providers.docker | unix:///var/run/docker.sock, exposedByDefault: false, network: nx-network | Router tự đăng ký qua labels |
providers.file | directory: /etc/traefik/dynamic, watch: true | Hot-reload middlewares.yml |
log | level: INFO, format: json | Log App/startup |
accessLog | format: json, bỏ Authorization + Cookie | Log theo từng request |
metrics.prometheus | entryPoint: traefik, nhãn entrypoint/router/service bật | Scrape trên :8080 |
2. Config động Traefik (Middlewares)
Nguồn: packages/gateway/config/dynamic/middlewares.yml
Định nghĩa router dashboard và tập middleware dùng chung được tham chiếu bởi Docker labels của dịch vụ với hậu tố @file. Phân tích đầy đủ: xem Middlewares.
| Middleware | Tóm tắt |
|---|---|
circuit-breaker | NetworkErrorRatio() > 0.10 || LatencyAtQuantileMS(95.0) > 3000 (vế tỷ lệ 5xx bị comment) |
rate-limit | 200/s, burst 400, ipStrategy.depth=1 |
rate-limit-auth | 30/min, burst 60, ipStrategy.depth=1 |
security-headers | XSS filter, nosniff, frame deny, strip Server/X-Powered-By |
dashboard-auth | basic auth (nx.eventry:…) cho Traefik dashboard + portal |
redirect-to-dashboard | ^/$ → /dashboard/ trên entrypoint traefik |
3. Bảng route Nginx cục bộ (Dev native)
Nguồn: packages/gateway/local/nginx.conf + local/docker-compose.yml
Container local-nx-gateway (nginx:1.27-alpine) chạy với host networking (chỉ Linux) nên nó bind :80 và tiếp cận các dịch vụ native trên 127.0.0.1:31xx. Path được forward nguyên văn — không rewrite — vì mỗi dịch vụ mount tại APP_ENV_SERVER_BASE_PATH riêng của nó.
Upstreams
| Dịch vụ | Upstream | Port |
|---|---|---|
| identity | identity_upstream | 127.0.0.1:31010 |
| commerce | commerce_upstream | 127.0.0.1:31020 |
| sale | sale_upstream | 127.0.0.1:31030 |
| finance | finance_upstream | 127.0.0.1:31040 |
| inventory | inventory_upstream | 127.0.0.1:31050 |
| ledger | ledger_upstream | 127.0.0.1:31060 |
| pricing | pricing_upstream | 127.0.0.1:31070 |
| payment | payment_upstream | 127.0.0.1:31080 |
| signal | signal_upstream | 127.0.0.1:31090 |
| outreach | outreach_upstream | 127.0.0.1:31110 |
| licensing | licensing_upstream | 127.0.0.1:31120 |
| taxation | taxation_upstream | 127.0.0.1:31130 |
| invoice | invoice_upstream | 127.0.0.1:31140 |
Locations
| Location | Đích | Ghi chú |
|---|---|---|
/v1/api/<svc>/ (13 ở trên) | upstream khớp | HTTP REST, forward nguyên văn |
= /stream | signal_upstream | Signal WebSocket; header Upgrade/Connection, timeout 3600s |
= /__gateway_health | — | Trả về 200 {"status":"ok","gateway":"local-nx-gateway"} |
/ | — | Không khớp → 404 {"error":"not found",...} (fail fast) |
Cài đặt
proxy_*dùng chung:proxy_http_version 1.1, forwardHost/X-Real-IP/X-Forwarded-*,client_max_body_size 50m, timeout read/send 300s. FE dùng một base URL duy nhất (http://sgw.local.bana.com.vn/v1/api).
4. Cấu hình Portal
Nguồn: packages/gateway/portal/astro.config.ts, portal/package.json
| Cài đặt | Giá trị |
|---|---|
| Output | static |
| Dev server | port 3003, host: true |
| Preview | port 4173 |
| Container port | 8080 (phục vụ bởi nginxinc/nginx-unprivileged:1.27-alpine) |
| Chunk warn limit | 400 kB |
Portal không phụ thuộc build-time vào các package backend. Nó khám phá dịch vụ tại runtime: nó suy ra base domain từ window.location.hostname (ví dụ sgw.develop.bana.com.vn → develop.bana.com.vn; SSR fallback develop.bana.com.vn) và fetch /health và /doc/openapi.json của mỗi dịch vụ.
5. Danh sách hằng số Service & App
Catalog của portal được duy trì thủ công dưới dạng hằng số TypeScript — nguồn duy nhất mà portal render từ đó.
Services — portal/src/constants/services.constant.ts
14 mục (Services.ITEMS), mỗi { id, name, pkg, icon, basePath, desc }:
| id | pkg | basePath |
|---|---|---|
| identity | @nx/identity | /v1/api/identity |
| commerce | @nx/commerce | /v1/api/commerce |
| sale | @nx/sale | /v1/api/sale |
| finance | @nx/finance | /v1/api/finance |
| inventory | @nx/inventory | /v1/api/inventory |
| payment | @nx/payment | /v1/api/payment |
| pricing | @nx/pricing | /v1/api/pricing |
| taxation | @nx/taxation | /v1/api/taxation |
| signal | @nx/signal | /v1/api/signal |
| ledger | @nx/ledger | /v1/api/ledger |
| invoice | @nx/invoice | /v1/api/invoice |
| outreach | @nx/outreach | /v1/api/outreach |
| licensing | @nx/licensing | /v1/api/licensing |
| helpdesk | @nx/helpdesk | /v1/api/helpdesk |
Ghi chú drift: portal liệt kê 14 dịch vụ (gồm
helpdesk); bảng route Nginx cục bộ liệt kê 13 (khônghelpdesk). AGENTS.md ghi "13 services" — source từ đó đã thêmhelpdesk. Đối chiếu lại khihelpdeskship một route.
Apps — portal/src/constants/apps.constant.ts
4 app frontend (Apps.ITEMS), URL được suy ra theo môi trường từ subdomain:
| id | name | subdomain |
|---|---|---|
| client | Client (admin dashboard) | client |
| bo | BO (back office) | bo |
| sale | Sale | sale |
| wiki | Wiki / Docs (VitePress) | docs |
6. Feature Flags / Dữ liệu Seed / Lưu trữ Cấu hình
N/A — gateway không có hệ thống feature-flag, không migration seed, và không bảng Configuration (không datastore).