Skip to content

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

SectionGiá trịGhi chú
api.dashboardtrueDashboard được bật (auth qua router file-provider, không phải api.insecure)
entryPoints.web:80Entrypoint HTTP — nhận traffic từ edge Nginx
entryPoints.traefik:8080Dashboard + Prometheus metrics
HTTPS entrypointvắngTLS kết thúc tại edge Nginx, không phải Traefik
providers.dockerunix:///var/run/docker.sock, exposedByDefault: false, network: nx-networkRouter tự đăng ký qua labels
providers.filedirectory: /etc/traefik/dynamic, watch: trueHot-reload middlewares.yml
loglevel: INFO, format: jsonLog App/startup
accessLogformat: json, bỏ Authorization + CookieLog theo từng request
metrics.prometheusentryPoint: traefik, nhãn entrypoint/router/service bậtScrape 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.

MiddlewareTóm tắt
circuit-breakerNetworkErrorRatio() > 0.10 || LatencyAtQuantileMS(95.0) > 3000 (vế tỷ lệ 5xx bị comment)
rate-limit200/s, burst 400, ipStrategy.depth=1
rate-limit-auth30/min, burst 60, ipStrategy.depth=1
security-headersXSS filter, nosniff, frame deny, strip Server/X-Powered-By
dashboard-authbasic 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ụUpstreamPort
identityidentity_upstream127.0.0.1:31010
commercecommerce_upstream127.0.0.1:31020
salesale_upstream127.0.0.1:31030
financefinance_upstream127.0.0.1:31040
inventoryinventory_upstream127.0.0.1:31050
ledgerledger_upstream127.0.0.1:31060
pricingpricing_upstream127.0.0.1:31070
paymentpayment_upstream127.0.0.1:31080
signalsignal_upstream127.0.0.1:31090
outreachoutreach_upstream127.0.0.1:31110
licensinglicensing_upstream127.0.0.1:31120
taxationtaxation_upstream127.0.0.1:31130
invoiceinvoice_upstream127.0.0.1:31140

Locations

LocationĐíchGhi chú
/v1/api/<svc>/ (13 ở trên)upstream khớpHTTP REST, forward nguyên văn
= /streamsignal_upstreamSignal WebSocket; header Upgrade/Connection, timeout 3600s
= /__gateway_healthTrả 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, forward Host/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 đặtGiá trị
Outputstatic
Dev serverport 3003, host: true
Previewport 4173
Container port8080 (phục vụ bởi nginxinc/nginx-unprivileged:1.27-alpine)
Chunk warn limit400 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.vndevelop.bana.com.vn; SSR fallback develop.bana.com.vn) và fetch /health/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 }:

idpkgbasePath
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ông helpdesk). AGENTS.md ghi "13 services" — source từ đó đã thêm helpdesk. Đối chiếu lại khi helpdesk ship 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:

idnamesubdomain
clientClient (admin dashboard)client
boBO (back office)bo
saleSalesale
wikiWiki / 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).

7. Trang liên quan

Proprietary and Confidential. Unauthorized copying, distribution, or use of this software is strictly prohibited.