Files
pda-overseas-uniapp/vite.config.js
T

66 lines
2.3 KiB
JavaScript
Raw Normal View History

2026-08-26 15:24:51 +08:00
import { defineConfig, loadEnv } from 'vite'
2026-08-20 20:10:20 +08:00
import uni from '@dcloudio/vite-plugin-uni'
2026-08-26 16:02:17 +08:00
function loggedProxy(name, options) {
return {
...options,
configure(proxy) {
proxy.on('proxyReq', (proxyRequest, request) => {
2026-08-26 16:50:25 +08:00
// The browser talks only to this same-origin Vite server. Forwarding its
// localhost Origin/Referer would make the upstream gateway run CORS
// validation again and reject the proxied request before Auth handles it.
proxyRequest.removeHeader('origin')
proxyRequest.removeHeader('referer')
2026-08-26 16:02:17 +08:00
console.info(`[Overseas PDA H5 proxy] ${name}`, `${request.method} ${request.url}`, '->', `${options.target}${proxyRequest.path}`)
})
proxy.on('proxyRes', (response, request) => {
console.info(`[Overseas PDA H5 proxy] ${name} response`, `${request.method} ${request.url}`, response.statusCode)
})
proxy.on('error', (error, request) => {
console.error(`[Overseas PDA H5 proxy] ${name} error`, `${request.method} ${request.url}`, error.message)
})
}
}
}
2026-08-26 15:24:51 +08:00
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '')
const domesticTarget = env.API_PROXY_TARGET || 'http://127.0.0.1:9000'
const overseasTarget = env.OVERSEAS_API_PROXY_TARGET || 'http://127.0.0.1:9300'
2026-09-20 14:22:17 +08:00
const preserveOverseasPrefix = env.OVERSEAS_API_PROXY_PRESERVE_PREFIX === 'true'
2026-08-26 15:24:51 +08:00
return {
2026-08-26 09:58:35 +08:00
plugins: [uni()],
2026-09-03 20:31:10 +08:00
define: {
__VUE_I18N_FULL_INSTALL__: true,
__VUE_I18N_LEGACY_API__: false,
__VUE_I18N_PROD_DEVTOOLS__: false,
__INTLIFY_PROD_DEVTOOLS__: false
},
2026-08-26 15:24:51 +08:00
server: {
proxy: {
2026-08-26 16:02:17 +08:00
'/api': loggedProxy('auth', { target: domesticTarget, changeOrigin: true }),
'/overseas-api': loggedProxy('overseas', {
2026-08-26 15:24:51 +08:00
target: overseasTarget,
changeOrigin: true,
2026-09-20 14:22:17 +08:00
rewrite: (path) => preserveOverseasPrefix ? path : path.replace(/^\/overseas-api/, '/api')
2026-08-26 16:02:17 +08:00
})
2026-08-26 15:24:51 +08:00
}
},
2026-08-26 09:58:35 +08:00
css: {
preprocessorOptions: {
scss: {
// DCloud uni-scss still uses APIs deprecated by the bundled Dart Sass.
// Keep real Sass warnings/errors visible while hiding these known notices.
silenceDeprecations: [
'legacy-js-api',
'import',
'global-builtin',
'color-functions',
'if-function'
]
}
}
}
2026-08-26 15:24:51 +08:00
}
2026-08-20 20:10:20 +08:00
})