312
This commit is contained in:
parent
8afdf5297f
commit
76308c41c4
|
|
@ -2,7 +2,6 @@ node_modules
|
||||||
dist
|
dist
|
||||||
.git
|
.git
|
||||||
.gitignore
|
.gitignore
|
||||||
.env
|
|
||||||
.env.local
|
.env.local
|
||||||
.env.*.local
|
.env.*.local
|
||||||
npm-debug.log*
|
npm-debug.log*
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
node_modules
|
node_modules
|
||||||
dist
|
|
||||||
.git
|
.git
|
||||||
.gitignore
|
.gitignore
|
||||||
.env
|
|
||||||
.env.local
|
.env.local
|
||||||
.env.*.local
|
.env.*.local
|
||||||
npm-debug.log*
|
npm-debug.log*
|
||||||
|
|
|
||||||
|
|
@ -1 +1,3 @@
|
||||||
|
# 生产环境配置
|
||||||
|
# API 基础 URL - 使用相对路径,由 nginx 代理到后端
|
||||||
VITE_API_BASE_URL=/api
|
VITE_API_BASE_URL=/api
|
||||||
3
src/frontend/.env.development
Normal file
3
src/frontend/.env.development
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
# 开发环境配置
|
||||||
|
# API 基础 URL - 开发环境直接访问后端
|
||||||
|
VITE_API_BASE_URL=/api
|
||||||
3
src/frontend/.env.production
Normal file
3
src/frontend/.env.production
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
# 生产环境配置
|
||||||
|
# API 基础 URL - 使用相对路径,由 nginx 代理到后端
|
||||||
|
VITE_API_BASE_URL=/api
|
||||||
|
|
@ -1,25 +1,8 @@
|
||||||
# 构建阶段
|
# 生产阶段 - 直接使用本地构建的 dist
|
||||||
FROM node:20-alpine AS builder
|
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
# 复制 package 文件
|
|
||||||
COPY package*.json ./
|
|
||||||
|
|
||||||
# 安装依赖
|
|
||||||
RUN npm install
|
|
||||||
|
|
||||||
# 复制源代码
|
|
||||||
COPY . .
|
|
||||||
|
|
||||||
# 构建生产版本
|
|
||||||
RUN npm run build
|
|
||||||
|
|
||||||
# 生产阶段
|
|
||||||
FROM nginx:alpine
|
FROM nginx:alpine
|
||||||
|
|
||||||
# 复制构建产物到 nginx
|
# 复制本地构建产物到 nginx
|
||||||
COPY --from=builder /app/dist /usr/share/nginx/html
|
COPY dist /usr/share/nginx/html
|
||||||
|
|
||||||
# 复制 nginx 配置
|
# 复制 nginx 配置
|
||||||
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { onMounted } from 'vue'
|
import { onMounted } from 'vue'
|
||||||
import { useAuthStore } from '@/stores/auth'
|
import { useAuthStore } from '@/stores/auth'
|
||||||
|
import BuildInfo from '@/components/BuildInfo.vue'
|
||||||
|
|
||||||
const authStore = useAuthStore()
|
const authStore = useAuthStore()
|
||||||
|
|
||||||
|
|
@ -11,6 +12,7 @@ onMounted(async () => {
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<router-view />
|
<router-view />
|
||||||
|
<BuildInfo />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import axios from 'axios'
|
||||||
import { tokenManager } from './client'
|
import { tokenManager } from './client'
|
||||||
import type { AuthResponse, LoginRequest, RegisterRequest } from '@/types'
|
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 {
|
function generateDeviceFingerprint(): string {
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import type { ApiResponse } from '@/types'
|
||||||
|
|
||||||
// 创建 axios 实例
|
// 创建 axios 实例
|
||||||
const apiClient: AxiosInstance = axios.create({
|
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,
|
timeout: 30000,
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
|
|
|
||||||
39
src/frontend/src/components/BuildInfo.vue
Normal file
39
src/frontend/src/components/BuildInfo.vue
Normal 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
4
src/frontend/src/env.d.ts
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
// 构建信息类型定义
|
||||||
|
declare const __BUILD_TIME__: string
|
||||||
|
declare const __API_BASE_URL__: string
|
||||||
|
declare const __BUILD_MODE__: string
|
||||||
|
|
@ -1,28 +1,37 @@
|
||||||
import { defineConfig } from 'vite'
|
import { defineConfig, loadEnv } from 'vite'
|
||||||
import vue from '@vitejs/plugin-vue'
|
import vue from '@vitejs/plugin-vue'
|
||||||
import { fileURLToPath, URL } from 'node:url'
|
import { fileURLToPath, URL } from 'node:url'
|
||||||
|
|
||||||
// https://vite.dev/config/
|
// https://vite.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig(({ mode }) => {
|
||||||
plugins: [vue()],
|
const env = loadEnv(mode, process.cwd(), '')
|
||||||
resolve: {
|
|
||||||
alias: {
|
return {
|
||||||
'@': fileURLToPath(new URL('./src', import.meta.url))
|
plugins: [vue()],
|
||||||
}
|
resolve: {
|
||||||
},
|
alias: {
|
||||||
server: {
|
'@': fileURLToPath(new URL('./src', import.meta.url))
|
||||||
port: 5173,
|
|
||||||
proxy: {
|
|
||||||
'/api': {
|
|
||||||
target: 'http://localhost:5000',
|
|
||||||
changeOrigin: true
|
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
},
|
define: {
|
||||||
css: {
|
__BUILD_TIME__: JSON.stringify(new Date().toLocaleString('zh-CN', { timeZone: 'Asia/Shanghai' })),
|
||||||
preprocessorOptions: {
|
__API_BASE_URL__: JSON.stringify(env.VITE_API_BASE_URL || '/api'),
|
||||||
scss: {
|
__BUILD_MODE__: JSON.stringify(mode)
|
||||||
additionalData: `@use "@/styles/variables" as *;`
|
},
|
||||||
|
server: {
|
||||||
|
port: 5173,
|
||||||
|
proxy: {
|
||||||
|
'/api': {
|
||||||
|
target: 'http://localhost:5000',
|
||||||
|
changeOrigin: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
css: {
|
||||||
|
preprocessorOptions: {
|
||||||
|
scss: {
|
||||||
|
additionalData: `@use "@/styles/variables" as *;`
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user