chore(mobile-h5): point Vite proxy at unified backend and add jsencrypt

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
zlwuandCursor committed 2026-08-03 22:27:47 +08:00
1 parent 26192676a2
commit f8f9c0ceff
4 files changed
+2125

No files matched your search

+4
View File
@@ -0,0 +1,4 @@
# 开发代理目标(Vite 用)
VITE_API_BASE_URL=http://127.0.0.1:8000
# 生产 API 前缀
VITE_API_URL=/api
+32
View File
@@ -0,0 +1,32 @@
{
"name": "mobile-h5",
"version": "1.0.0",
"type": "module",
"scripts": {
"dev": "vite --open",
"build": "vue-tsc --noEmit && vite build",
"preview": "vite preview"
},
"dependencies": {
"axios": "^1.7.5",
"dayjs": "^1.11.19",
"html2canvas": "^1.4.1",
"jsencrypt": "^3.5.4",
"mitt": "^3.0.1",
"pinia": "^2.2.2",
"vant": "^4.9.21",
"vue": "^3.5.12",
"vue-router": "^4.4.2"
},
"devDependencies": {
"@types/node": "^22.1.0",
"@vitejs/plugin-vue": "^5.2.1",
"@vue/tsconfig": "^0.1.3",
"sass": "^1.81.0",
"typescript": "~5.6.3",
"unplugin-auto-import": "^0.18.3",
"unplugin-vue-components": "^0.27.4",
"vite": "^6.1.0",
"vue-tsc": "~2.1.6"
}
}
+1995
View File
File diff suppressed because it is too large. Load diff
+94
View File
@@ -0,0 +1,94 @@
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
import Components from 'unplugin-vue-components/vite'
import AutoImport from 'unplugin-auto-import/vite'
import { VantResolver } from 'unplugin-vue-components/resolvers'
export default defineConfig(({ mode }) => {
// 加载环境变量
const env = loadEnv(mode, process.cwd(), '')
const apiBaseUrl = env.VITE_API_BASE_URL || 'http://127.0.0.1:8000'
// 打印代理配置(仅在开发环境)
if (mode === 'development') {
console.log('🔧 Vite Proxy Config:')
console.log(' Target:', apiBaseUrl)
console.log(' Path: /api -> forwarded with /api prefix (no rewrite)')
}
return {
base: './',
server: {
port: 5174,
proxy: {
'/api': {
target: apiBaseUrl,
changeOrigin: true,
secure: false,
configure: (proxy, options) => {
proxy.on('error', (err, req, res) => {
console.log('❌ Proxy error:', err)
})
proxy.on('proxyReq', (proxyReq, req, res) => {
const originalUrl = req.url || ''
if (originalUrl && !originalUrl.endsWith('/')) {
const [path, query] = originalUrl.split('?')
const pathParts = path.split('/').filter(Boolean)
if (pathParts.length === 2 && pathParts[0] === 'api') {
const resource = pathParts[1]
const listResources = ['plans', 'inventory', 'weighing']
if (listResources.includes(resource)) {
const newPath = path + '/' + (query ? '?' + query : '')
proxyReq.path = newPath
req.url = newPath
console.log(
`➡️ Proxying: ${req.method} ${originalUrl} -> ${apiBaseUrl}${newPath} (added trailing slash)`
)
return
}
}
}
console.log(`➡️ Proxying: ${req.method} ${req.url} -> ${apiBaseUrl}${req.url}`)
})
proxy.on('proxyRes', (proxyRes, req, res) => {
console.log(`⬅️ Response: ${req.url} -> ${proxyRes.statusCode}`)
})
}
}
},
host: true
},
resolve: {
alias: {
'@': path.resolve(__dirname, 'src')
}
},
plugins: [
vue(),
Components({
resolvers: [VantResolver()],
dts: 'src/types/components.d.ts',
dirs: ['src/components'],
extensions: ['vue']
}),
AutoImport({
imports: ['vue', 'vue-router', 'pinia'],
dts: 'src/types/auto-imports.d.ts',
eslintrc: {
enabled: true,
filepath: './.auto-import.json',
globalsPropValue: true
}
})
],
css: {
preprocessorOptions: {
scss: {
additionalData: `@use "@/assets/styles/variables.scss" as *;`
}
}
}
}
})