1
This commit is contained in:
+20
-3
@@ -1,6 +1,23 @@
|
||||
import { defineConfig, loadEnv } from 'vite'
|
||||
import uni from '@dcloudio/vite-plugin-uni'
|
||||
|
||||
function loggedProxy(name, options) {
|
||||
return {
|
||||
...options,
|
||||
configure(proxy) {
|
||||
proxy.on('proxyReq', (proxyRequest, request) => {
|
||||
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)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default defineConfig(({ mode }) => {
|
||||
const env = loadEnv(mode, process.cwd(), '')
|
||||
const domesticTarget = env.API_PROXY_TARGET || 'http://127.0.0.1:9000'
|
||||
@@ -9,12 +26,12 @@ export default defineConfig(({ mode }) => {
|
||||
plugins: [uni()],
|
||||
server: {
|
||||
proxy: {
|
||||
'/api': { target: domesticTarget, changeOrigin: true },
|
||||
'/overseas-api': {
|
||||
'/api': loggedProxy('auth', { target: domesticTarget, changeOrigin: true }),
|
||||
'/overseas-api': loggedProxy('overseas', {
|
||||
target: overseasTarget,
|
||||
changeOrigin: true,
|
||||
rewrite: (path) => path.replace(/^\/overseas-api/, '/api')
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
css: {
|
||||
|
||||
Reference in New Issue
Block a user