From ec61f134a81087805d7f0186306a8c30906870a9 Mon Sep 17 00:00:00 2001 From: wangys <3401275564@qq.com> Date: Fri, 2 Jan 2026 18:22:09 +0800 Subject: [PATCH] =?UTF-8?q?web=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dockerignore | 1 - docker/nginx/docker-compose.yml | 9 +- docker/nginx/volumes/conf.d/default.conf | 131 ++++++++++++++++++ docker/nginx/volumes/nginx.conf | 47 +++++++ .../urbanLifeline/serv/config/bootstrap.yml | 10 +- docker/urbanLifeline/web/Dockerfile.web | 6 +- .../web/config/app-config-shared.js | 48 +++++++ docker/urbanLifeline/web/web-manager.sh | 5 +- .../packages/bidding/vite.config.ts | 4 +- .../packages/platform/vite.config.ts | 4 +- .../packages/workcase/vite.config.ts | 4 +- 11 files changed, 246 insertions(+), 23 deletions(-) create mode 100644 docker/nginx/volumes/conf.d/default.conf create mode 100644 docker/nginx/volumes/nginx.conf create mode 100644 docker/urbanLifeline/web/config/app-config-shared.js diff --git a/.dockerignore b/.dockerignore index 5e4ff85f..eeff46e4 100644 --- a/.dockerignore +++ b/.dockerignore @@ -32,7 +32,6 @@ docker/**/volumes/ **/node_modules/ # 排除构建产物(保留 JAR 文件) -**/dist/ **/build/ # 排除 target 下的非 JAR 文件 **/target/classes/ diff --git a/docker/nginx/docker-compose.yml b/docker/nginx/docker-compose.yml index 13656163..eec84f3c 100644 --- a/docker/nginx/docker-compose.yml +++ b/docker/nginx/docker-compose.yml @@ -17,14 +17,11 @@ services: environment: TZ: Asia/Shanghai volumes: - - ${DATA_ROOT:-../volumes}/nginx/logs:/var/log/nginx - - ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro - - ./nginx/conf.d:/etc/nginx/conf.d:ro + - ./volumes/nginx/logs:/var/log/nginx + - ./volumes/nginx.conf:/etc/nginx/nginx.conf:ro + - ./volumes/conf.d:/etc/nginx/conf.d:ro # SSL 证书(可选) # - ./nginx/ssl:/etc/nginx/ssl:ro - depends_on: - - urban-lifeline-serv - - urban-lifeline-web healthcheck: test: ["CMD", "curl", "-f", "http://localhost/health"] interval: 30s diff --git a/docker/nginx/volumes/conf.d/default.conf b/docker/nginx/volumes/conf.d/default.conf new file mode 100644 index 00000000..28ad83e9 --- /dev/null +++ b/docker/nginx/volumes/conf.d/default.conf @@ -0,0 +1,131 @@ +# ================================================ +# Urban Lifeline - 站点配置 (All-in-One 模式) +# ================================================ + +# 上游服务定义 - 后端 All-in-One 容器 +upstream gateway { + server urban-lifeline-serv:8080; + keepalive 32; +} + +# 上游服务定义 - 前端 All-in-One 容器 +upstream shared { + server urban-lifeline-web:8000; +} + +upstream platform { + server urban-lifeline-web:8001; +} + +upstream workcase-web { + server urban-lifeline-web:8002; +} + +upstream bidding-web { + server urban-lifeline-web:8003; +} + +upstream workcase-wechat { + server urban-lifeline-web:8004; +} + +server { + listen 80; + server_name localhost; + + # 健康检查端点 + location /health { + access_log off; + return 200 "healthy\n"; + add_header Content-Type text/plain; + } + + # ====================== 前端应用代理 ====================== + + # Shared 公共模块 (Module Federation 远程模块) + location /shared/ { + proxy_pass http://shared/; + proxy_http_version 1.1; + 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; + + # 允许跨域 (Module Federation 需要) + add_header Access-Control-Allow-Origin *; + add_header Access-Control-Allow-Methods "GET, OPTIONS"; + add_header Access-Control-Allow-Headers "Origin, Content-Type, Accept"; + } + + # Platform 管理平台 + location /platform/ { + proxy_pass http://platform/; + proxy_http_version 1.1; + 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; + } + + # Workcase 工单系统 PC端 + location /workcase/ { + proxy_pass http://workcase-web/; + proxy_http_version 1.1; + 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; + } + + # Bidding 招标系统 + location /bidding/ { + proxy_pass http://bidding-web/; + proxy_http_version 1.1; + 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; + } + + # Workcase 工单系统微信端 + location /workcase-wechat/ { + proxy_pass http://workcase-wechat/; + proxy_http_version 1.1; + 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; + } + + # 默认首页(重定向到 platform) + location = / { + return 302 /platform/; + } + + # ====================== API 代理 ====================== + + # 后端 API 代理 + location /urban-lifeline/ { + proxy_pass http://gateway/urban-lifeline/; + proxy_http_version 1.1; + 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; + + # WebSocket 支持 + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + + # 超时设置 + proxy_connect_timeout 60s; + proxy_send_timeout 60s; + proxy_read_timeout 60s; + } + + # ====================== 错误页面 ====================== + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } +} diff --git a/docker/nginx/volumes/nginx.conf b/docker/nginx/volumes/nginx.conf new file mode 100644 index 00000000..ed8a2477 --- /dev/null +++ b/docker/nginx/volumes/nginx.conf @@ -0,0 +1,47 @@ +# ================================================ +# Urban Lifeline - Nginx 主配置 +# ================================================ + +user nginx; +worker_processes auto; +error_log /var/log/nginx/error.log warn; +pid /var/run/nginx.pid; + +events { + worker_connections 1024; + use epoll; + multi_accept on; +} + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + # 日志格式 + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + + # 性能优化 + sendfile on; + tcp_nopush on; + tcp_nodelay on; + keepalive_timeout 65; + types_hash_max_size 2048; + + # Gzip 压缩 + gzip on; + gzip_vary on; + gzip_proxied any; + gzip_comp_level 6; + gzip_types text/plain text/css text/xml application/json application/javascript + application/xml application/xml+rss text/javascript application/x-javascript; + + # 上传文件大小限制 + client_max_body_size 100M; + + # 引入站点配置 + include /etc/nginx/conf.d/*.conf; +} diff --git a/docker/urbanLifeline/serv/config/bootstrap.yml b/docker/urbanLifeline/serv/config/bootstrap.yml index 1f807a68..6b203fe0 100644 --- a/docker/urbanLifeline/serv/config/bootstrap.yml +++ b/docker/urbanLifeline/serv/config/bootstrap.yml @@ -8,21 +8,21 @@ spring: cloud: nacos: discovery: - server-addr: ${NACOS_SERVER_ADDR:nacos:8848} + server-addr: ${NACOS_SERVER_ADDR:urban-lifeline-nacos:8848} namespace: ${NACOS_NAMESPACE:} group: ${NACOS_GROUP:DEFAULT_GROUP} # ================== DataSource ================== datasource: - url: ${DB_URL:jdbc:postgresql://postgres:5432/urban_lifeline} + url: ${DB_URL:jdbc:postgresql://urban-lifeline-pg:5432/urban_lifeline} username: ${DB_USERNAME:postgres} - password: ${DB_PASSWORD:postgres} + password: ${DB_PASSWORD:postgres123456} driver-class-name: org.postgresql.Driver # ================== Redis ================== data: redis: - host: ${REDIS_HOST:redis} + host: ${REDIS_HOST:urban-lifeline-redis} port: ${REDIS_PORT:6379} database: ${REDIS_DATABASE:0} password: ${REDIS_PASSWORD:} @@ -38,7 +38,7 @@ dubbo: name: dubbo port: -1 registry: - address: nacos://${NACOS_SERVER_ADDR:nacos:8848} + address: nacos://${NACOS_SERVER_ADDR:urban-lifeline-nacos:8848} # ================== MyBatis-Plus ================== mybatis-plus: diff --git a/docker/urbanLifeline/web/Dockerfile.web b/docker/urbanLifeline/web/Dockerfile.web index b55b7695..a76aca75 100644 --- a/docker/urbanLifeline/web/Dockerfile.web +++ b/docker/urbanLifeline/web/Dockerfile.web @@ -28,7 +28,7 @@ COPY urbanLifelineWeb/packages/shared/dist/ /app/sites/shared/ COPY urbanLifelineWeb/packages/platform/dist/ /app/sites/platform/ COPY urbanLifelineWeb/packages/workcase/dist/ /app/sites/workcase/ COPY urbanLifelineWeb/packages/bidding/dist/ /app/sites/bidding/ -COPY urbanLifelineWeb/packages/workcase_wechat/dist/ /app/sites/workcase_wechat/ +# COPY urbanLifelineWeb/packages/workcase_wechat/dist/ /app/sites/workcase_wechat/ # ============================================ # 端口配置 (可通过环境变量覆盖) @@ -36,8 +36,8 @@ COPY urbanLifelineWeb/packages/workcase_wechat/dist/ /app/sites/workcase_wechat/ ENV SHARED_PORT=8000 \ PLATFORM_PORT=8001 \ WORKCASE_PORT=8002 \ - BIDDING_PORT=8003 \ - WORKCASE_WECHAT_PORT=8004 + BIDDING_PORT=8003 + # WORKCASE_WECHAT_PORT=8004 # 配置和日志目录 (可外挂) VOLUME ["/app/config", "/app/logs"] diff --git a/docker/urbanLifeline/web/config/app-config-shared.js b/docker/urbanLifeline/web/config/app-config-shared.js new file mode 100644 index 00000000..df3ffddd --- /dev/null +++ b/docker/urbanLifeline/web/config/app-config-shared.js @@ -0,0 +1,48 @@ +/** + * Shared 运行时配置 (Docker 部署) + * 此文件会被挂载到容器中,覆盖构建时的默认配置 + */ +window.APP_RUNTIME_CONFIG = { + env: 'production', + + api: { + baseUrl: '/api', + timeout: 30000 + }, + + baseUrl: '/', + + file: { + downloadUrl: '/api/urban-lifeline/file/download/', + uploadUrl: '/api/urban-lifeline/file/upload', + maxSize: { + image: 5, + video: 100, + document: 10 + }, + acceptTypes: { + image: 'image/*', + video: 'video/*', + document: '.pdf,.doc,.docx,.xls,.xlsx,.ppt,.pptx' + } + }, + + token: { + key: 'token', + refreshThreshold: 300000 + }, + + publicImgPath: '/img', + publicWebPath: '/', + + sso: { + platformUrl: 'https://demo-urbanlifeline.tensorgrove.com/', + workcaseUrl: 'https://demo-urbanlifeline.tensorgrove.com/workcase', + biddingUrl: 'https://demo-urbanlifeline.tensorgrove.com/bidding' + }, + + features: { + enableDebug: false, + enableMockData: false + } +}; diff --git a/docker/urbanLifeline/web/web-manager.sh b/docker/urbanLifeline/web/web-manager.sh index cea6d9e3..15e0a3a5 100644 --- a/docker/urbanLifeline/web/web-manager.sh +++ b/docker/urbanLifeline/web/web-manager.sh @@ -58,11 +58,12 @@ declare -A WEBS=( ["platform"]="PLATFORM_PORT:8001" ["workcase"]="WORKCASE_PORT:8002" # ["bidding"]="BIDDING_PORT:8003" - ["workcase_wechat"]="WORKCASE_WECHAT_PORT:8004" + # ["workcase_wechat"]="WORKCASE_WECHAT_PORT:8004" ) # shared 必须最先启动 (其他模块依赖它) -BOOT_ORDER=(shared platform workcase bidding workcase_wechat) +# BOOT_ORDER=(shared platform workcase bidding workcase_wechat) +BOOT_ORDER=(shared platform workcase) # 颜色 RED='\033[0;31m' diff --git a/urbanLifelineWeb/packages/bidding/vite.config.ts b/urbanLifelineWeb/packages/bidding/vite.config.ts index 5f8c2dbb..41bd952d 100644 --- a/urbanLifelineWeb/packages/bidding/vite.config.ts +++ b/urbanLifelineWeb/packages/bidding/vite.config.ts @@ -10,9 +10,9 @@ const __filename = fileURLToPath(import.meta.url) const __dirname = dirname(__filename) // 开发环境 shared 模块地址 -const DEV_SHARED_URL = 'https://localhost:7000/shared/mf-manifest.json' +const DEV_SHARED_URL = 'https://localhost:7000/shared/remoteEntry.js' // 生产环境使用相对路径,通过 Nginx 代理访问 -const PROD_SHARED_URL = '/shared/mf-manifest.json' +const PROD_SHARED_URL = '/shared/remoteEntry.js' export default defineConfig(({ mode }) => { const isDev = mode === 'development' diff --git a/urbanLifelineWeb/packages/platform/vite.config.ts b/urbanLifelineWeb/packages/platform/vite.config.ts index 82b62c2a..f8a2d7b5 100644 --- a/urbanLifelineWeb/packages/platform/vite.config.ts +++ b/urbanLifelineWeb/packages/platform/vite.config.ts @@ -10,9 +10,9 @@ const __filename = fileURLToPath(import.meta.url) const __dirname = dirname(__filename) // 开发环境 shared 模块地址 -const DEV_SHARED_URL = 'https://localhost:7000/shared/mf-manifest.json' +const DEV_SHARED_URL = 'https://localhost:7000/shared/remoteEntry.js' // 生产环境使用相对路径,通过 Nginx 代理访问 -const PROD_SHARED_URL = '/shared/mf-manifest.json' +const PROD_SHARED_URL = '/shared/remoteEntry.js' export default defineConfig(({ mode }) => { const isDev = mode === 'development' diff --git a/urbanLifelineWeb/packages/workcase/vite.config.ts b/urbanLifelineWeb/packages/workcase/vite.config.ts index 71d8cbe4..8e818588 100644 --- a/urbanLifelineWeb/packages/workcase/vite.config.ts +++ b/urbanLifelineWeb/packages/workcase/vite.config.ts @@ -10,9 +10,9 @@ const __filename = fileURLToPath(import.meta.url) const __dirname = dirname(__filename) // 开发环境 shared 模块地址 -const DEV_SHARED_URL = 'https://localhost:7000/shared/mf-manifest.json' +const DEV_SHARED_URL = 'https://localhost:7000/shared/remoteEntry.js' // 生产环境使用相对路径,通过 Nginx 代理访问 -const PROD_SHARED_URL = '/shared/mf-manifest.json' +const PROD_SHARED_URL = '/shared/remoteEntry.js' export default defineConfig(({ mode }) => { const isDev = mode === 'development'