feat(frontend): configure API proxy target for development environment
Updated the Vite configuration to allow dynamic setting of the API proxy target based on environment variables. The default target is now configurable via VITE_DEV_PROXY_TARGET or FRONTEND_BACKEND_URL, enhancing flexibility for different development setups. Additionally, the development script logs the current API proxy target for better visibility during startup.
This commit is contained in:
@@ -11,6 +11,10 @@ const require = createRequire(import.meta.url)
|
|||||||
|
|
||||||
const pkg = require('./package.json') as { version?: string }
|
const pkg = require('./package.json') as { version?: string }
|
||||||
const FRONTEND_VERSION = pkg.version ?? 'unknown'
|
const FRONTEND_VERSION = pkg.version ?? 'unknown'
|
||||||
|
const DEV_PROXY_TARGET =
|
||||||
|
process.env.VITE_DEV_PROXY_TARGET ||
|
||||||
|
process.env.FRONTEND_BACKEND_URL ||
|
||||||
|
'http://localhost:8080'
|
||||||
|
|
||||||
function resolveVueOfficePptxEntry(): string {
|
function resolveVueOfficePptxEntry(): string {
|
||||||
try {
|
try {
|
||||||
@@ -47,12 +51,12 @@ export default defineConfig({
|
|||||||
// 代理配置,用于开发环境
|
// 代理配置,用于开发环境
|
||||||
proxy: {
|
proxy: {
|
||||||
'/api': {
|
'/api': {
|
||||||
target: 'http://localhost:8080',
|
target: DEV_PROXY_TARGET,
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
secure: false,
|
secure: false,
|
||||||
},
|
},
|
||||||
'/files': {
|
'/files': {
|
||||||
target: 'http://localhost:8080',
|
target: DEV_PROXY_TARGET,
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
secure: false,
|
secure: false,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -319,6 +319,7 @@ start_frontend() {
|
|||||||
|
|
||||||
log_info "启动 Vite 开发服务器..."
|
log_info "启动 Vite 开发服务器..."
|
||||||
log_info "前端将运行在 http://localhost:5173"
|
log_info "前端将运行在 http://localhost:5173"
|
||||||
|
log_info "前端 API 代理目标: ${VITE_DEV_PROXY_TARGET:-${FRONTEND_BACKEND_URL:-http://localhost:8080}}"
|
||||||
|
|
||||||
# 运行开发服务器
|
# 运行开发服务器
|
||||||
npm run dev
|
npm run dev
|
||||||
|
|||||||
Reference in New Issue
Block a user