You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
szkp-map-h5/vite.tianditu-proxy.ts

29 lines
841 B

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<string, ProxyOptions> {
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,
},
}
}