提交
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import { defineConfig, loadEnv } from 'vite'
|
||||
import uni from '@dcloudio/vite-plugin-uni'
|
||||
|
||||
function loggedProxy(options) {
|
||||
return {
|
||||
...options,
|
||||
configure(proxy) {
|
||||
proxy.on('proxyReq', (proxyRequest, request) => {
|
||||
proxyRequest.removeHeader('origin')
|
||||
proxyRequest.removeHeader('referer')
|
||||
console.info('[Domestic PDA H5 proxy]', `${request.method} ${request.url}`, '->', `${options.target}${proxyRequest.path}`)
|
||||
})
|
||||
proxy.on('proxyRes', (response, request) => {
|
||||
console.info('[Domestic PDA H5 proxy response]', `${request.method} ${request.url}`, response.statusCode)
|
||||
})
|
||||
proxy.on('error', (error, request) => {
|
||||
console.error('[Domestic PDA H5 proxy error]', `${request.method} ${request.url}`, error.message)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default defineConfig(({ mode }) => {
|
||||
const projectRoot = process.env.UNI_INPUT_DIR || process.cwd()
|
||||
const env = loadEnv(mode, projectRoot, '')
|
||||
const proxyTarget = env.API_PROXY_TARGET || 'http://127.0.0.1:9000'
|
||||
|
||||
return {
|
||||
plugins: [uni()],
|
||||
server: {
|
||||
proxy: {
|
||||
'/gateway-api': loggedProxy({
|
||||
target: proxyTarget,
|
||||
changeOrigin: true,
|
||||
rewrite: (path) => path.replace(/^\/gateway-api/, '/api')
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user