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(), '')
|
2026-09-29 17:56:05 +08:00
|
|
|
const apiTarget = env.API_PROXY_TARGET || 'http://127.0.0.1:9000'
|
2026-08-26 15:24:51 +08:00
|
|
|
return {
|
2026-09-30 14:27:37 +08:00
|
|
|
base: process.env.UNI_PLATFORM === 'h5' && mode === 'production' ? '/' : undefined,
|
2026-08-26 09:58:35 +08:00
|
|
|
plugins: [uni()],
|
2026-09-03 20:31:10 +08:00
|
|
|
define: {
|
2026-09-29 20:57:40 +08:00
|
|
|
'import.meta.env.VITE_PDA_UPDATE_URL': JSON.stringify(env.VITE_PDA_UPDATE_URL || ''),
|
|
|
|
|
'import.meta.env.VITE_PDA_DEV_USERNAME': JSON.stringify(env.VITE_PDA_DEV_USERNAME || ''),
|
|
|
|
|
'import.meta.env.VITE_PDA_DEV_PASSWORD': JSON.stringify(env.VITE_PDA_DEV_PASSWORD || ''),
|
2026-09-03 20:31:10 +08:00
|
|
|
__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-09-30 14:27:37 +08:00
|
|
|
'/gateway-api': loggedProxy('api', {
|
|
|
|
|
target: apiTarget, changeOrigin: true,
|
|
|
|
|
rewrite: (path) => path.replace(/^\/gateway-api/, '/api')
|
|
|
|
|
})
|
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
|
|
|
})
|