import type { ProxyOptions } from 'vite' const DEV_REFERER = process.env.VITE_TIANDITU_DEV_REFERER?.trim() || 'https://szkp-map.langye.net/' const refererOnProxy: ProxyOptions['configure'] = (proxy) => { proxy.on('proxyReq', (proxyReq) => { proxyReq.setHeader('Referer', DEV_REFERER) }) } export function tiandituDevProxy(): Record { return { '/tianditu-tile-proxy': { target: 'https://t0.tianditu.gov.cn', changeOrigin: true, secure: true, rewrite: (path) => path.replace(/^\/tianditu-tile-proxy/, ''), configure: refererOnProxy, }, '/tianditu-api-proxy': { target: 'https://api.tianditu.gov.cn', changeOrigin: true, secure: true, rewrite: (path) => path.replace(/^\/tianditu-api-proxy/, ''), configure: refererOnProxy, }, } }