From 1714ff19f539fa6a2ea48bf0cb4fda9cfd9b7f68 Mon Sep 17 00:00:00 2001 From: lianlonggang Date: Fri, 12 Sep 2025 17:33:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8DOCKER=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E5=8F=98=E9=87=8F=E6=9B=BF=E6=8D=A2=E7=BD=91=E5=85=B3=E9=93=BE?= =?UTF-8?q?=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.production | 9 --------- Dockerfile | 13 ++++++++++++- entrypoint.sh | 9 +++++++++ index.html | 5 ++++- package.json | 2 ++ src/utils/env.ts | 38 ++++++++++++++++++++++++++++++++------ 6 files changed, 59 insertions(+), 17 deletions(-) create mode 100644 entrypoint.sh diff --git a/.env.production b/.env.production index d9d4379..d6f909b 100644 --- a/.env.production +++ b/.env.production @@ -1,12 +1,3 @@ #后台地址 VITE_GLOB_API_URL=https://api.xjygjk.com -#健康监测工具报警-websocket -VITE_GLOB_API_YIN_JI=wss://api.xjygjk.com/health-watch/websocket/watchMonitor -#应急求助-websocket -VITE_GLOB_API_JIAN_CE=wss://api.xjygjk.com/health-emergency/websocket/emergency - -#西安云坐席 -VITE_GLOB_API_XIAN_YUN=wss://api.xjygjk.com/health-emergency/websocket/emergency3 -#银川云坐席 -VITE_GLOB_API_YIN_CHUAN=wss://api.xjygjk.com/health-emergency/websocket/emergency4 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 36018e4..703afe3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,6 +2,9 @@ FROM nginx MAINTAINER jeecgos@163.com VOLUME /tmp ENV LANG en_US.UTF-8 + +ENV VITE_GLOB_API_URL https://api.xjygjk.com + RUN echo "server { \ #解决Router(mode: 'history')模式下,刷新路由地址不能找到页面的问题 \ location / { \ @@ -18,4 +21,12 @@ RUN echo "server { \ && mkdir -p /var/www/html ADD dist/ /var/www/html/ -EXPOSE 3101 + +# 👇 新增:复制启动脚本(用于运行时替换环境变量) +COPY entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh + +# 使用脚本作为入口点 +ENTRYPOINT ["/entrypoint.sh"] + +EXPOSE 80 diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..2514ee0 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +# 设置默认值(构建时 .env 不生效时兜底) +: ${VITE_GLOB_API_URL:=https://api.xjygjk.com} + +# 替换 index.html 中的占位符 +sed -i "s@__VITE_GLOB_API_URL__@$VITE_GLOB_API_URL@g" /var/www/html/index.html + +exec nginx -g 'daemon off;' \ No newline at end of file diff --git a/index.html b/index.html index 742dbf3..37395f8 100644 --- a/index.html +++ b/index.html @@ -7,7 +7,10 @@ 应急就医服务中心