proxy.ts 376 B

12345678910111213141516
  1. import type { ProxyOptions } from 'vite'
  2. export function createViteProxy(isOpenProxy: boolean, viteEnv: ImportMetaEnv) {
  3. if (!isOpenProxy)
  4. return
  5. const proxy: Record<string, string | ProxyOptions> = {
  6. '/api': {
  7. target: viteEnv.VITE_APP_API_BASE_URL,
  8. changeOrigin: true,
  9. rewrite: path => path.replace('/api/', '/'),
  10. },
  11. }
  12. return proxy
  13. }