docker配置修改

This commit is contained in:
Hongying Li
2026-04-12 19:04:31 +08:00
parent 5dd16d9809
commit aed9323a09
3 changed files with 26 additions and 11 deletions

View File

@@ -1,18 +1,13 @@
FROM node:18-alpine AS builder
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
# NAS部署非常关键的一步由于走Nginx同域反代需将URL置空以使用相对路径避免局域网IP锁死
# NAS部署使用相对路径以便让Vite Preview接管同域/api路由并代理给backend容器
ENV VITE_API_BASE_URL=""
RUN npm run build
FROM nginx:alpine
# 获取vite构件结果
COPY --from=builder /app/dist /usr/share/nginx/html
# 覆盖Nginx默认配置
COPY nginx.conf /etc/nginx/conf.d/default.conf
# 暴露的Web服务器访问端口
EXPOSE 80
# 安装一个轻量静态服务器 (http-server 或 serve),或者直接使用 vite preview
EXPOSE 8090
CMD ["npm", "run", "preview", "--", "--host", "0.0.0.0", "--port", "8090"]

View File

@@ -38,4 +38,24 @@ export default defineConfig({
},
},
},
server: {
port: 8090,
host: '0.0.0.0',
proxy: {
'/api': {
target: 'http://backend:8080',
changeOrigin: true
}
}
},
preview: {
port: 8090,
host: '0.0.0.0',
proxy: {
'/api': {
target: 'http://backend:8080',
changeOrigin: true
}
}
}
})