import { defineConfig } from 'vite'
import uni from '@dcloudio/vite-plugin-uni'

// https://vitejs.dev/config/
export default defineConfig({
    plugins: [uni()],
    server: {
        // 配置开发服务器
        port: 5173,
        host: '0.0.0.0',
        // 配置代理解决 H5 端跨域问题
        proxy: {
            '/api': {
                target: 'https://flaunt.batiao8.com',
                changeOrigin: true,
                secure: false,
                ws: true,
                configure: (proxy, options) => {
                    proxy.on('proxyReq', (proxyReq, req, res) => {
                        console.log('[Vite Proxy] 请求:', req.method, req.url, '→', options.target + req.url);
                    });
                    proxy.on('proxyRes', (proxyRes, req, res) => {
                        console.log('[Vite Proxy] 响应:', proxyRes.statusCode, req.url);
                    });
                    proxy.on('error', (err, req, res) => {
                        console.error('[Vite Proxy] 代理错误:', err.message);
                    });
                }
            }
        }
    }
})
