This commit is contained in:
code@server 2025-12-18 01:00:14 +08:00
parent 8afdf5297f
commit 76308c41c4
12 changed files with 87 additions and 45 deletions

View File

@ -2,7 +2,6 @@ node_modules
dist
.git
.gitignore
.env
.env.local
.env.*.local
npm-debug.log*

View File

@ -1,8 +1,6 @@
node_modules
dist
.git
.gitignore
.env
.env.local
.env.*.local
npm-debug.log*

View File

@ -1 +1,3 @@
# 生产环境配置
# API 基础 URL - 使用相对路径,由 nginx 代理到后端
VITE_API_BASE_URL=/api

View File

@ -0,0 +1,3 @@
# 开发环境配置
# API 基础 URL - 开发环境直接访问后端
VITE_API_BASE_URL=/api

View File

@ -0,0 +1,3 @@
# 生产环境配置
# API 基础 URL - 使用相对路径,由 nginx 代理到后端
VITE_API_BASE_URL=/api

View File

@ -1,25 +1,8 @@
# 构建阶段
FROM node:20-alpine AS builder
WORKDIR /app
# 复制 package 文件
COPY package*.json ./
# 安装依赖
RUN npm install
# 复制源代码
COPY . .
# 构建生产版本
RUN npm run build
# 生产阶段
# 生产阶段 - 直接使用本地构建的 dist
FROM nginx:alpine
# 复制构建产物到 nginx
COPY --from=builder /app/dist /usr/share/nginx/html
# 复制本地构建产物到 nginx
COPY dist /usr/share/nginx/html
# 复制 nginx 配置
COPY nginx.conf /etc/nginx/conf.d/default.conf

View File

@ -1,6 +1,7 @@
<script setup lang="ts">
import { onMounted } from 'vue'
import { useAuthStore } from '@/stores/auth'
import BuildInfo from '@/components/BuildInfo.vue'
const authStore = useAuthStore()
@ -11,6 +12,7 @@ onMounted(async () => {
<template>
<router-view />
<BuildInfo />
</template>
<style>

View File

@ -2,7 +2,7 @@ import axios from 'axios'
import { tokenManager } from './client'
import type { AuthResponse, LoginRequest, RegisterRequest } from '@/types'
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || 'http://localhost:5000/api'
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || '/api'
// 生成设备指纹
function generateDeviceFingerprint(): string {

View File

@ -3,7 +3,7 @@ import type { ApiResponse } from '@/types'
// 创建 axios 实例
const apiClient: AxiosInstance = axios.create({
baseURL: import.meta.env.VITE_API_BASE_URL || 'http://localhost:5000/api',
baseURL: import.meta.env.VITE_API_BASE_URL || '/api',
timeout: 30000,
headers: {
'Content-Type': 'application/json'

View File

@ -0,0 +1,39 @@
<template>
<div class="build-info">
<span>构建时间: {{ buildTime }}</span>
<span class="separator">|</span>
<span>API: {{ apiBaseUrl }}</span>
<span class="separator">|</span>
<span>模式: {{ buildMode }}</span>
</div>
</template>
<script setup lang="ts">
const buildTime = __BUILD_TIME__
const apiBaseUrl = __API_BASE_URL__
const buildMode = __BUILD_MODE__
</script>
<style scoped>
.build-info {
position: fixed;
bottom: 0;
left: 0;
right: 0;
background: rgba(0, 0, 0, 0.7);
color: #fff;
padding: 8px 16px;
font-size: 12px;
text-align: center;
z-index: 9999;
display: flex;
justify-content: center;
align-items: center;
gap: 8px;
font-family: monospace;
}
.separator {
color: #666;
}
</style>

4
src/frontend/src/env.d.ts vendored Normal file
View File

@ -0,0 +1,4 @@
// 构建信息类型定义
declare const __BUILD_TIME__: string
declare const __API_BASE_URL__: string
declare const __BUILD_MODE__: string

View File

@ -1,28 +1,37 @@
import { defineConfig } from 'vite'
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import { fileURLToPath, URL } from 'node:url'
// https://vite.dev/config/
export default defineConfig({
plugins: [vue()],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
},
server: {
port: 5173,
proxy: {
'/api': {
target: 'http://localhost:5000',
changeOrigin: true
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '')
return {
plugins: [vue()],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
}
},
css: {
preprocessorOptions: {
scss: {
additionalData: `@use "@/styles/variables" as *;`
},
define: {
__BUILD_TIME__: JSON.stringify(new Date().toLocaleString('zh-CN', { timeZone: 'Asia/Shanghai' })),
__API_BASE_URL__: JSON.stringify(env.VITE_API_BASE_URL || '/api'),
__BUILD_MODE__: JSON.stringify(mode)
},
server: {
port: 5173,
proxy: {
'/api': {
target: 'http://localhost:5000',
changeOrigin: true
}
}
},
css: {
preprocessorOptions: {
scss: {
additionalData: `@use "@/styles/variables" as *;`
}
}
}
}