diff --git a/backend/Dockerfile b/backend/Dockerfile index 12e99b4..3c912ce 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -15,5 +15,8 @@ RUN pip install --upgrade pip && pip install -r requirements.txt # Copy project COPY . /app/ +# Expose port +EXPOSE 8000 + # Run the application CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"] diff --git a/backend/requirements.txt b/backend/requirements.txt index 41f80ac..1ffa959 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -17,3 +17,4 @@ rpds-py==0.30.0 sqlparse==0.5.5 uritemplate==4.2.0 wechatpayv3==2.0.1 +drf-spectacular-sidecar==2026.1.1 diff --git a/backend/shop/__pycache__/views.cpython-313.pyc b/backend/shop/__pycache__/views.cpython-313.pyc index 7e83a10..b7fcf84 100644 Binary files a/backend/shop/__pycache__/views.cpython-313.pyc and b/backend/shop/__pycache__/views.cpython-313.pyc differ diff --git a/backend/shop/admin.py b/backend/shop/admin.py index bf3593c..b60089e 100644 --- a/backend/shop/admin.py +++ b/backend/shop/admin.py @@ -160,8 +160,8 @@ class SalespersonAdmin(ModelAdmin): total_sales_display.short_description = "累计销售额 (已支付)" def promotion_url(self, obj): - # 假设前端部署在 localhost:5173,生产环境需配置 - base_url = "http://localhost:5173" + # 假设前端部署在 localhost:15173,生产环境需配置 + base_url = "http://localhost:15173" return f"{base_url}/?ref={obj.code}" @display(description="推广链接") diff --git a/docker-compose.yml b/docker-compose.yml index f34d066..961da48 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -19,7 +19,7 @@ services: - ./frontend:/app - /app/node_modules ports: - - "5173:5173" + - "15173:15173" environment: - VITE_API_URL=http://localhost:8000/api depends_on: diff --git a/frontend/Dockerfile b/frontend/Dockerfile index c21d2dd..500402c 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -1,5 +1,5 @@ # Use an official Node runtime as a parent image -FROM node:18-alpine +FROM node:22-alpine # Set working directory WORKDIR /app @@ -8,11 +8,17 @@ WORKDIR /app COPY package.json package-lock.json* ./ RUN npm install -# Copy project files +# 复制项目文件 COPY . . -# Expose the port the app runs on -EXPOSE 5173 +# 设置环境变量供构建时使用 +ENV VITE_API_URL=http://localhost:8000/api -# Start the application -CMD ["npm", "run", "dev", "--", "--host"] +# 构建生产环境代码 +RUN npm run build + +# 暴露应用运行的端口 +EXPOSE 15173 + +# 启动应用 (Preview 模式) +CMD ["npm", "run", "preview", "--", "--host", "0.0.0.0", "--port", "15173"] diff --git a/frontend/vite.config.js b/frontend/vite.config.js index 8b0f57b..7335060 100644 --- a/frontend/vite.config.js +++ b/frontend/vite.config.js @@ -1,7 +1,16 @@ import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' +//123 // https://vite.dev/config/ export default defineConfig({ plugins: [react()], + server: { + host: '0.0.0.0', + port: 5173, + }, + preview: { + host: '0.0.0.0', + port: 15173, + } })