feat: 拆分路由
This commit is contained in:
parent
162e57e80d
commit
f9e5a33590
|
|
@ -1,7 +1,7 @@
|
||||||
# 接口地址
|
# 接口地址
|
||||||
VITE_AMAP_KEY = 6888d721d30981b479ecdabd85f286fe
|
VITE_AMAP_KEY=6888d721d30981b479ecdabd85f286fe
|
||||||
VITE_AMAP_SAFE_KEY = 23d3fdbc6b4eaf65d4a82a16510938c9
|
VITE_AMAP_SAFE_KEY=23d3fdbc6b4eaf65d4a82a16510938c9
|
||||||
VITE_REGISTER_SOURCE = ALL
|
VITE_REGISTER_SOURCE=ALL
|
||||||
#VITE_REGISTER_SOURCE = XM001
|
#VITE_REGISTER_SOURCE=XM001
|
||||||
VITE_SHOW_PAY = SUCCESS
|
VITE_SHOW_PAY=SUCCESS
|
||||||
VITE_API_URL = http://47.86.170.114:8011/api
|
VITE_API_URL=http://111.230.37.169:10004/api
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
# 端口
|
# 端口(等号两侧不要空格,避免解析出带空格的 target)
|
||||||
VITE_PORT = 8887
|
VITE_PORT=8887
|
||||||
VITE_API_URL = http://47.86.170.114:8011/api
|
# 仅 dev 时给 vite 代理用;若与 .env.development.local 冲突,以 .local 为准
|
||||||
|
VITE_API_URL=http://47.86.170.114:8011/api
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
# 是否生成打包分析图表
|
|
||||||
VITE_VISUALIZER = false
|
|
||||||
VITE_API_URL = https://api.undressing.name/api
|
|
||||||
|
|
@ -20,8 +20,13 @@ const messages = i18n.global.messages[lang];
|
||||||
* @constant
|
* @constant
|
||||||
* @desc 创建axios实例
|
* @desc 创建axios实例
|
||||||
*/
|
*/
|
||||||
|
// Vite 仅注入 import.meta.env(VITE_*);勿用 process.env.VUE_APP_BASE_API(Vue CLI)
|
||||||
|
// 开发:走相对路径 + vite 代理 /dev-api;生产:直连 .env 中的 VITE_API_URL(与后端同域时可留空并在构建里写死路径)
|
||||||
const service = axios.create({
|
const service = axios.create({
|
||||||
baseURL: process.env.VUE_APP_BASE_API,
|
baseURL:
|
||||||
|
import.meta.env.MODE === 'development'
|
||||||
|
? ''
|
||||||
|
: (import.meta.env.VITE_API_URL || ''),
|
||||||
withCredentials: import.meta.env.MODE === 'development',
|
withCredentials: import.meta.env.MODE === 'development',
|
||||||
timeout: 600 * 1000
|
timeout: 600 * 1000
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,8 @@ export default defineConfig({
|
||||||
less: {
|
less: {
|
||||||
modifyVars: {
|
modifyVars: {
|
||||||
'@size-9': '40px',
|
'@size-9': '40px',
|
||||||
'arcoblue-6': '#e6217a'
|
// 主色:青霓虹(替代原品红),与暗色壳层搭配
|
||||||
|
'arcoblue-6': '#22d3ee'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,24 +1,55 @@
|
||||||
import { defineConfig, mergeConfig, loadEnv } from 'vite'
|
import { defineConfig, mergeConfig, loadEnv } from 'vite'
|
||||||
|
import { dirname, resolve } from 'path'
|
||||||
|
import { fileURLToPath } from 'url'
|
||||||
import baseViteConfig from './vite.config'
|
import baseViteConfig from './vite.config'
|
||||||
|
|
||||||
const env = loadEnv('development', process.cwd())
|
const __dirname = dirname(fileURLToPath(import.meta.url))
|
||||||
|
|
||||||
|
/** 代理只能用「协议+主机+端口」,不能带 path;否则转发路径容易错 */
|
||||||
|
function devProxyTarget(apiBaseUrl) {
|
||||||
|
if (!apiBaseUrl || typeof apiBaseUrl !== 'string') {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const u = new URL(apiBaseUrl)
|
||||||
|
return `${u.protocol}//${u.host}`
|
||||||
|
} catch {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 与 portal-ui 根目录一致加载 .env*(ESM 下必须用 import.meta.url,不能依赖未定义的 __dirname)
|
||||||
|
const env = loadEnv('development', resolve(__dirname))
|
||||||
|
|
||||||
|
const apiBase = env.VITE_API_URL?.trim() || ''
|
||||||
|
const proxyTarget = devProxyTarget(apiBase)
|
||||||
|
|
||||||
|
if (!proxyTarget) {
|
||||||
|
console.warn(
|
||||||
|
'[vite] VITE_API_URL 未配置或无效,/dev-api 代理未启用。请在 .env.development 中设置,例如:VITE_API_URL=http://47.86.170.114:8011/api'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const devConfig = defineConfig({
|
const devConfig = defineConfig({
|
||||||
server: {
|
server: {
|
||||||
host: env.VITE_HOST || 'localhost',
|
host: env.VITE_HOST || 'localhost',
|
||||||
port: env.VITE_PORT || 8081,
|
port: Number(env.VITE_PORT) || 8081,
|
||||||
open: true,
|
open: true,
|
||||||
watch: {
|
watch: {
|
||||||
ignored: [/node_modules/, /dist/, /deploy/]
|
ignored: [/node_modules/, /dist/, /deploy/]
|
||||||
},
|
},
|
||||||
|
...(proxyTarget
|
||||||
|
? {
|
||||||
proxy: {
|
proxy: {
|
||||||
'/dev-api': {
|
'/dev-api': {
|
||||||
target: env.VITE_API_URL,
|
target: proxyTarget,
|
||||||
ws: false,
|
ws: false,
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
rewrite: (path) => path.replace(/^\/dev-api/, '')
|
rewrite: (path) => path.replace(/^\/dev-api/, '')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
: {})
|
||||||
|
}
|
||||||
})
|
})
|
||||||
export default mergeConfig(baseViteConfig, devConfig)
|
export default mergeConfig(baseViteConfig, devConfig)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue