import { defineConfig } from 'vite'
import { devtools } from '@tanstack/devtools-vite'

import { tanstackStart } from '@tanstack/react-start/plugin/vite'

import viteReact from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/vite'

const config = defineConfig({
  resolve: { tsconfigPaths: true },

  // Dev only: same-origin /api and /ws like production (Apache), so cookies and
  // the backend's Origin check work. Set APP_URL=http://localhost:3000 in backend/.env.
  server: {
    proxy: {
      '/api': 'http://127.0.0.1:3001',
      '/ws': { target: 'ws://127.0.0.1:3001', ws: true },
    },
  },

  preview: {
    host: '0.0.0.0',
    port: 3200,
    allowedHosts: ['namail.nandalinux.my.id'],
  },

  plugins: [devtools(), tailwindcss(), tanstackStart(), viteReact()],
})

export default config
