1
This commit is contained in:
@@ -11,6 +11,8 @@ function authRequest(path, data) {
|
||||
success(response) {
|
||||
const body = response.data || {}
|
||||
console.info('[Overseas PDA auth] response', { url, statusCode: response.statusCode, code: body.code,
|
||||
message: typeof body === 'object' ? body.message : String(body).slice(0, 160),
|
||||
contentType: response.header?.['Content-Type'] || response.header?.['content-type'],
|
||||
requestId: body.requestId || response.header?.['X-Request-Id'] || response.header?.['x-request-id'],
|
||||
traceId: body.traceId || response.header?.['X-Trace-Id'] || response.header?.['x-trace-id'] })
|
||||
if (String(body.code ?? response.statusCode) !== '200') {
|
||||
|
||||
+1
-5
@@ -81,11 +81,7 @@
|
||||
"vueVersion": "3",
|
||||
"h5": {
|
||||
"devServer": {
|
||||
"proxy": {
|
||||
|
||||
},
|
||||
"port" : 5176,
|
||||
"https": false
|
||||
"port": 5176
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+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