import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

// https://vite.dev/config/
export default defineConfig({
  plugins: [react()],
  test: {
    environment: 'jsdom',
    globals: true,
    setupFiles: ['./src/test-setup.js'],
    include: ['src/**/*.test.{js,jsx}'],
  },
  server: {
    host: '127.0.0.1',
    port: 3007,
    strictPort: false,
    proxy: {
      '/api': {
        target: 'https://gahusb.synology.me',
        changeOrigin: true,
        secure: true,
      },
      // 여행 사진 미디어 파일 (/media/travel/...)
      '/media': {
        target: 'https://gahusb.synology.me',
        changeOrigin: true,
        secure: true,
      },
      // Fear & Greed Index (CNN 공개 API)
      // 프로덕션 nginx에서는 아래 proxy_pass 추가 필요:
      //   location /ext/feargreed {
      //     proxy_pass https://production.dataviz.cnn.io/index/fearandgreed/graphdata;
      //     proxy_set_header Host production.dataviz.cnn.io;
      //   }
      '/ext/feargreed': {
        target: 'https://production.dataviz.cnn.io',
        changeOrigin: true,
        secure: true,
        rewrite: () => '/index/fearandgreed/graphdata',
      },
      // VIX (CBOE 변동성 지수) — Yahoo Finance 공개 API
      // 프로덕션 nginx에서는 아래 proxy_pass 추가 필요:
      //   location /ext/vix {
      //     proxy_pass https://query1.finance.yahoo.com/v8/finance/chart/%5EVIX?interval=1d&range=1d;
      //     proxy_set_header Host query1.finance.yahoo.com;
      //   }
      '/ext/vix': {
        target: 'https://query1.finance.yahoo.com',
        changeOrigin: true,
        secure: true,
        rewrite: () => '/v8/finance/chart/%5EVIX?interval=1d&range=1d',
      },
      // 미국 10년물 국채 금리 (^TNX) — Yahoo Finance
      // 프로덕션 nginx 설정 필요:
      //   location /ext/treasury {
      //     proxy_pass https://query1.finance.yahoo.com/v8/finance/chart/%5ETNX?interval=1d&range=1d;
      //     proxy_set_header Host query1.finance.yahoo.com;
      //   }
      '/ext/treasury': {
        target: 'https://query1.finance.yahoo.com',
        changeOrigin: true,
        secure: true,
        rewrite: () => '/v8/finance/chart/%5ETNX?interval=1d&range=1d',
      },
      // WTI 원유 선물 (CL=F) — Yahoo Finance
      // 프로덕션 nginx 설정 필요:
      //   location /ext/wti {
      //     proxy_pass https://query1.finance.yahoo.com/v8/finance/chart/CL%3DF?interval=1d&range=1d;
      //     proxy_set_header Host query1.finance.yahoo.com;
      //   }
      '/ext/wti': {
        target: 'https://query1.finance.yahoo.com',
        changeOrigin: true,
        secure: true,
        rewrite: () => '/v8/finance/chart/CL%3DF?interval=1d&range=1d',
      },
      // Brent 원유 선물 (BZ=F) — Yahoo Finance
      // 프로덕션 nginx 설정 필요:
      //   location /ext/brent {
      //     proxy_pass https://query1.finance.yahoo.com/v8/finance/chart/BZ%3DF?interval=1d&range=1d;
      //     proxy_set_header Host query1.finance.yahoo.com;
      //   }
      '/ext/brent': {
        target: 'https://query1.finance.yahoo.com',
        changeOrigin: true,
        secure: true,
        rewrite: () => '/v8/finance/chart/BZ%3DF?interval=1d&range=1d',
      },
    },
  },
})
