| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- import { fileURLToPath, URL } from 'node:url'
- import vue from '@vitejs/plugin-vue'
- import { defineConfig, loadEnv, type ProxyOptions } from 'vite'
- function cookieToToken(proxy: { on: (ev: string, fn: (...args: any[]) => void) => void }) {
- proxy.on('proxyReq', (proxyReq: { setHeader: (k: string, v: string) => void }, req: { headers: { cookie?: string } }) => {
- const cookie = req.headers.cookie || ''
- const hit = /(?:^|;\s*)DmsToken=([^;]+)/.exec(cookie)
- if (!hit) return
- const token = decodeURIComponent(hit[1])
- proxyReq.setHeader('Token', token)
- proxyReq.setHeader('token', token)
- })
- }
- function dmsProxy(gateway: string): Record<string, ProxyOptions> {
- return {
- '/proxy_oauth': {
- target: gateway,
- changeOrigin: true,
- },
- '/proxy_dms': {
- target: gateway,
- changeOrigin: true,
- configure: cookieToToken,
- },
- }
- }
- export default defineConfig(({ mode }) => {
- const env = loadEnv(mode, process.cwd(), '')
- const gateway = env.DMS_GATEWAY || 'http://121.43.55.7:2101'
- const proxy = dmsProxy(gateway)
- return {
- plugins: [vue()],
- resolve: {
- alias: {
- '@': fileURLToPath(new URL('./src', import.meta.url)),
- },
- },
- server: {
- host: true,
- port: 5173,
- proxy,
- },
- preview: {
- proxy,
- },
- }
- })
|